Android TextView背景顏色與背景圖片設置


Android TextView 背景顏色與背景圖片設置,android textview 控件,android textview 背景,

android textview 圖片,android textview 顏色,android textview 組件,android textview background 。

設置文本顏色

TextView textView = (TextView) findViewById(R.id.textview1); 
// 使用實際的顏色值設置字體顏色
textView.setTextColor(android.graphics.Color.RED); 

設置背景顏色
有三種方法:

setBackgroundResource:通過顏色資源ID設置背景色。
setBackgroundColor:通過顏色值設置背景色。
setBackgroundDrawable:通過Drawable對象設置背景色。

下面分別演示如何用這3個方法來設置TextView組件的背景

setBackgroundResource方法設置背景:

textView.setBackgroundResource(R.color.background);  

setBackgroundColor方法設置背景:
textView.setBackgroundColor(android.graphics.Color.RED);

setBackgroundDrawable方法設置背景:
Resources resources=getBaseContext().getResources(); 
Drawable drawable=resources.getDrawable(R.color.background); 
textView.setBackgroundDrawable(drawable); 

 

設置背景圖片

1、將背景圖片放置在 drawable-mdpi 目錄下,假設圖片名為 bgimg.jpg 。

2、main.xml 文件

<EditText
   android:layout_width="fill_parent"
   android:layout_height="wrap_content" 
   android:background="@drawable/bgimg"
/>

 

 

 

 

ANDROID TEXTVIEW 背景顏色與背景圖片設置
2014-06-26 16:34:51  By: dwtedx

Android TextView 背景顏色與背景圖片設置,android textview 控件,android textview 背景,

android textview 圖片,android textview 顏色,android textview 組件,android textview background 。

 

設置文本顏色

 

TextView textView =(TextView) findViewById(R.id.textview1);// 使用實際的顏色值設置字體顏色
textView.setTextColor(android.graphics.Color.RED);

設置背景顏色

有三種方法:

setBackgroundResource:通過顏色資源ID設置背景色。
setBackgroundColor:通過顏色值設置背景色。
setBackgroundDrawable:通過Drawable對象設置背景色。

 


下面分別演示如何用這3個方法來設置TextView組件的背景


setBackgroundResource方法設置背景:

 

以下為引用內容: 
textView.setBackgroundResource(R.color.background);  

setBackgroundColor方法設置背景:
textView.setBackgroundColor(android.graphics.Color.RED);

setBackgroundDrawable方法設置背景:Resources resources=getBaseContext().getResources();Drawable drawable=resources.getDrawable(R.color.background); 
textView.setBackgroundDrawable(drawable);

設置背景圖片

 


1、將背景圖片放置在 drawable-mdpi 目錄下,假設圖片名為 bgimg.jpg 。


2、main.xml 文件


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM