textview顏色android
『壹』 Android 中 textview點擊改變文字顏色 並在點擊另一個textView時變回原來的顏色
private TextView mTextDisp; mTextDisp = (TextView) findViewById(R.id.textDisp_mian); mTextDisp.setTextColor(R.color.red);(使用color.xml文件中的顏色值) 這樣寫是怎麼也變不成紅色的,而且程序不報錯,不知道朋友們有沒有試過。而且debug所走的分支也是正確的。 我就單獨寫了一個Demo來測試,結果還是灰顯。 有的朋友要說,是不是red的顏色值寫錯了。不是,color中的顏色值配置對著呢。 其實,答案很簡單,就錯在mTextDisp.setTextColor(R.color.red);這行代碼上。 首先,在xml中不要寫默認的字體顏色值,即android:textColor="xxx" 其次,在activity中mTextDisp.setTextColor(context.getResources().getColor(R.color.red));(使用color.xml文件中的顏色值) 這樣就OK了。或者直接使用Color類中的值:mTextDisp.setTextColor(Color.RED);(使用系統自帶的顏色類Color類中的顏色值)。
『貳』 android,在線性布局中如何改變裡面所有textView的文字顏色呢要用到函數嗎
1、自定義TextView並改變字體顏色,把xml布局裡面的全替換成你這個;
2、在代碼界面,通過查找子View來遍歷,如果子view是TextView則改字體顏色
『叄』 關於Android TextView
android系統的文本視圖的意思。
TextView是android裡面用的最多的控制項,TextView類似一般UI中的Label,TextBlock等控制項,只是為了單純的顯示一行或多行文本。TextView作為android開發中最簡單也最常用的控制項,作為初學者,需要熟知其屬性並熟練掌握。
android:cursorVisible設定游標為顯示/隱藏,默認顯示。
android:digits設置允許輸入哪些字元。如「1234567890.+-*/% ()」
android:drawableBottom在text的下方輸出一個drawable,如圖片。如果指定一個顏色的話會text的背景設為該顏色,並且同時和background使用時覆蓋後者。
android:drawableLeft在text的左邊輸出一個drawable,如圖片。
android:drawablePadding設置text與drawable(圖片)的間隔,與drawableLeft、 drawableRight、drawableTop、drawableBottom一起使用,可設置為負數,單獨使用沒有效果。
android:drawableRight在text的右邊輸出一個drawable。
android:drawableTop在text的正上方輸出一個drawable。
android:editable設置是否可編輯。
android:editorExtras設置文本的額外的輸入數據。
android:ellipsize設置當文字過長時,該控制項該如何顯示。有如下值設置:」start」—-省略號顯示在開頭;」end」 ——省略號顯示在結尾;」middle」—-省略號顯示在中間;」marquee」 ——以跑馬燈的方式顯示(動畫橫向移動)
android:freezesText設置保存文本的內容以及游標的位置。
android:gravity設置文本位置,如設置成「center」,文本將居中顯示。
android:hintText為空時顯示的文字提示信息,可通過textColorHint設置提示信息的顏色。此屬性在 EditView中使用,但是這里也可以用。
android:imeOptions附加功能,設置右下角IME動作與編輯框相關的動作,如actionDone右下角將顯示一個「完成」,而不設置默認是一個回車符號。這個在EditView中再詳細說明,此處無用。
android:imeActionId設置IME動作ID。
android:imeActionLabel設置IME動作標簽。
android:includeFontPadding設置文本是否包含頂部和底部額外空白,默認為true。
android:inputMethod為文本指定輸入法,需要完全限定名(完整的包名)。
android:inputType設置文本的類型,用於幫助輸入法顯示合適的鍵盤類型。在EditView中再詳細說明,這里無效果。
android:linksClickable設置鏈接是否點擊連接,即使設置了autoLink。
android:marqueeRepeatLimit在ellipsize指定marquee的情況下,設置重復滾動的次數,當設置為 marquee_forever時表示無限次。
android:ems設置TextView的寬度為N個字元的寬度。這里測試為一個漢字字元寬度
android:maxEms設置TextView的寬度為最長為N個字元的寬度。與ems同時使用時覆蓋ems選項。
android:minEms設置TextView的寬度為最短為N個字元的寬度。與ems同時使用時覆蓋ems選項。
android:maxLength限制顯示的文本長度,超出部分不顯示。
android:lines設置文本的行數,設置兩行就顯示兩行,即使第二行沒有數據。
android:maxLines設置文本的最大顯示行數,與width或者layout_width結合使用,超出部分自動換行,超出行數將不顯示。
android:minLines設置文本的最小行數,與lines類似。
android:lineSpacingExtra設置行間距。
android:lineSpacingMultiplier設置行間距的倍數。如」1.2」
android:numeric如果被設置,該TextView有一個數字輸入法。此處無用,設置後唯一效果是TextView有點擊效果,此屬性在EdtiView將詳細說明。
android:password以小點」.」顯示文本
android:phoneNumber設置為電話號碼的輸入方式。
android:privateImeOptions設置輸入法選項,此處無用,在EditText將進一步討論。
android:scrollHorizontally設置文本超出TextView的寬度的情況下,是否出現橫拉條。
android:selectAllOnFocus如果文本是可選擇的,讓他獲取焦點而不是將游標移動為文本的開始位置或者末尾位置。 TextView中設置後無效果。
android:shadowColor指定文本陰影的顏色,需要與shadowRadius一起使用。
android:shadowDx設置陰影橫向坐標開始位置。
android:shadowDy設置陰影縱向坐標開始位置。
android:shadowRadius設置陰影的半徑。設置為0.1就變成字體的顏色了,一般設置為3.0的效果比較好。
android:singleLine設置單行顯示。如果和layout_width一起使用,當文本不能全部顯示時,後面用「…」來表示。
android:singleLine="true" android:layout_width="20dp"將只顯示「t…」。如果不設置singleLine或者設置為false,文本將自動換行
android:text設置顯示文本.
android:textAppearance設置文字外觀。如 「?android:attr/textAppearanceLargeInverse」這里引用的是系統自帶的一個外觀,?表示系統是否有這種外觀,否則使用默認的外觀。可設置的值如下:textAppearanceButton/textAppearanceInverse/textAppearanceLarge/textAppearanceLargeInverse/textAppearanceMedium/textAppearanceMediumInverse/textAppearanceSmall/textAppearanceSmallInverse
android:textColor設置文本顏色
android:textColorHighlight被選中文字的底色,默認為藍色
android:textColorHint設置提示信息文字的顏色,默認為灰色。與hint一起使用。
android:textColorLink文字鏈接的顏色.
android:textScaleX設置文字之間間隔,默認為1.0f。
android:textSize設置文字大小,推薦度量單位」sp」,如」15sp」
android:textStyle設置字形[bold(粗體) 0, italic(斜體) 1, bolditalic(又粗又斜) 2] 可以設置一個或多個,用「|」隔開
android:typeface設置文本字體,必須是以下常量值之一:normal 0, sans 1, serif 2,
monospace(等寬字體) 3]
android:height設置文本區域的高度,支持度量單位:px(像素)/dp/sp/in/mm(毫米)
android:maxHeight設置文本區域的最大高度
android:minHeight設置文本區域的最小高度
android:width設置文本區域的寬度,支持度量單位:px(像素)/dp/sp/in/mm(毫米),與layout_width 的區別看這里
android:maxWidth設置文本區域的最大寬度
android:minWidth設置文本區域的最小寬度
『肆』 android 如何設置TextView中字體在不同狀態下的顏色
TextView的字體設置方法:
1、直接通過配置文件設置
2、在Activity類中進行設置
第一種方式很簡單,用於靜態或初始文字顏色的設置,方法如下:
main.xml
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
>
<TextView
android:id="@+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
android:textColor="@color/red"
/>
</LinearLayout>
color.xml
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
</resources>
drawable.xml
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="white">#FFFFFF</drawable>
<drawable name="dark">#000000</drawable>
<drawable name="red">#FF0000</drawable>
</resources>
strings.xml
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">地址:http://yahaitt.javaeye.com</string>
<string name="app_name">丫梨的筆記本</string>
</resources>
上面將資源部分分成了3個部分,目的是為了清晰,當然你也可以只建一個xml文件放在res目錄下,而且文件名稱可以隨便命名。
注意兩個地方:
1、main.xml的TextView標簽中:
android:textColor="@color/red"
2、color.xml中:
<color name="red">#FF0000</color>
@color指獲取資源文件中(所有res目錄下的xml文件)的<color>標簽
/red指在標簽下找其name值為red的內容,此時其值為#FF0000
因此,這里我們還可以這樣做:
android:textColor="@drawable/red"
@drawable指獲取資源文件中<drawable>標簽
/red指在標簽下找其name值為red的內容
以此類推,相信你也就知道了如果是在strings.xml中該怎麼做了。
下面看看第二種方式:在Activity類中進行設置
1、先將main.xml改成如下,即去掉android:textColor="@color/red":
Xml代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/white"
>
<TextView
android:id="@+id/tv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:autoLink="all"
/>
</LinearLayout>
2、修改Activity的onCreate方法,這里我的Activity是Study03_01,原始代碼如下:
Java代碼
package yahaitt.study03_01;
import android.app.Activity;
import android.os.Bundle;
public class Study03_01 extends Activity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
第一步:獲得文本控制項TextView,取名為tv
第二步:通過TextView的setTextColor方法進行文本顏色的設置,這里可以有3種方式進行設置:
第1種:tv.setTextColor(android.graphics.Color.RED);//系統自帶的顏色類
第2種:tv.setTextColor(0xffff00ff);//0xffff00ff是int類型的數據,分組一下0x|ff|ff00ff,0x是代表顏色整數的標記,ff是表示透明度,ff00ff表示顏色,注意:這里ffff00ff必須是8個的顏色表示,不接受ff00ff這種6個的顏色表示。
第3種:tv.setTextColor(this.getResources().getColor(R.color.red));//通過獲得資源文件進行設置。根據不同的情況R.color.red也可以是R.string.red或者R.drawable.red,當然前提是需要在相應的配置文件里做相應的配置,如:
<color name="red">#FF0000</color>
<drawable name="red">#FF0000</drawable>
<string name="red">#FF0000</string>
詳細的代碼如下:
Java代碼
package yahaitt.study03_01;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;
public class Study03_01 extends Activity {
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView)this.findViewById(R.id.tv01);
// tv.setTextColor(Color.RED);
// tv.setTextColor(0xff000000);
『伍』 android 顏色設置 textview 代碼中怎麼設置"#FFF"的三原色
通過如下代碼設置十六進制顏色:
extView tv = new TextView(this);
tv.setText("Test set TextView's color.");
//方案一:代碼中通過argb值的方式
tv.setTextColor(Color.rgb(255, 255, 255));
『陸』 android開發,在代碼中怎麼獲取textView的背景顏色
直接上代碼吧,注釋解說:
TextView tText=(TextView) findViewById(R.id.textv_name);
//第1種:
tText.setTextColor(android.graphics.Color.RED);//系統自帶的顏色類
// 第2種:
tText.setTextColor(0xffff00ff);//0xffff00ff是int類型的數據,分組一下0x|ff|ff00ff,0x是代表顏色整數的標記,ff是表示透明度,ff00ff表示顏色,注意:這里ffff00ff必須是8個的顏色表示,不接受ff00ff這種6個的顏色表示。
//第3種:
tText.setTextColor(android.graphics.Color.parseColor("#87CEFA")) ; //還是利用Color類;(比如http://www.tiecou.com/)
//第4種:
tText.setTextColor(this.getResources().getColor(R.color.red));
/*通過獲得資源文件進行設置。根據不同的情況R.color.red也可以是R.string.red或者R.drawable.red,
* 當然前提是需要在相應的配置文件里做相應的配置,如(xml 標簽):
*
* <color name="red">#FF0000</color>
<drawable name="red">#FF0000</drawable>
<string name="red">#FF0000</string>*/
『柒』 如何在android textview 設置背景色
通常來說,每個界面都對應一個activity。而在activity的View視圖中,可以在最外層容器去設置背景圖片或背景顏色。
在xml布局裡:
android:background="@drawable/img1"
或者
android:background="@color/white"
在java代碼里,也可以設置
layout.setBackgroundColor(R.color.white);
layout.setBackgroundDrawable(drawable);
layout.setBackgroundResource(R.drawable.img1);
再者,系統默認的背景色是能過theme來控制的,就是說創建一個activity的背景色,如果在
AndroidManifest.xml文件里有設置如下:
android:theme="@android:style/Theme"
這樣設置activity的主題樣式,"@android:style/Theme"一般是系統默認的。這個不單是背景色,還有其它的樣式,具體可以在網上查一下android:theme的用法。
而"@android:style/Theme"的背景色就是黑色。
『捌』 android textview系統默認的顏色值是多少
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="西堤牛排"
android:id="@+id/top"
android:textSize="40dip"(大小)
android:textColor="#000000"(顏色)
/>
『玖』 安卓開發:如何靜態和動態設置textView的文本和背景色彩,如何填初學不知填啥.要詳細
靜態就是在可視化的Graphical Layout內的屬性內填
textView1.TextColor(文本色)
textView1.Background(背景色)
中填 @android就會自動彈出所有定義的色彩值
如 @android:color/holo_blue_bright
動態就是程序中設定色彩
import android.graphics.Color;
textView1.setTextColor(Color.RED);
textView1.setBackgroundColor(Color.RED);
『拾』 android TextView怎麼設置個別字體顏色並換行
1、TextView 設置個別字體顏色
TextViewtv=(TextView)findViewById(R.id.tv);
tv.setText(Html.fromHtml("你的內容:<fontcolor=red>要設置的內容</font>"));
2、TextView 設置字體換行
TextViewtv=(TextView)findViewById(R.id.tv);
tv.setText("你的內容");
3、TextView 設置個別字體顏色並換行
TextViewtv=(TextView)findViewById(R.id.tv);
tv.setText(Html.fromHtml("內容:<br/><fontcolor=red>juapk.com</font>"));
或者可以用SpannableString 設置字體顏色
StringXM="asd";
SpannableStringmsp=newSpannableString("測試"+XM+"更換當前號碼將從手機發送一條普通簡訊進行驗證");
2msp.setSpan(newForegroundColorSpan(Color.BLUE),2,XM.length()+2,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
