導航:首頁 > 操作系統 > androidtextview文字顏色

androidtextview文字顏色

發布時間:2022-06-01 00:49:13

① 安卓開發:如何靜態和動態設置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:在java類中 TextView tv = new TextView(this); tv.setTextColor(Color.RED);利用這種方式設置字體顏色。 2:在xml文件中 在你的TextView中有textColor屬性,給屬性值為RGB格式就行了.

③ Android編程問題:改變TextView中指定字體顏色

TextView htmlFormateTextView = (TextView)findViewById(R.id.testTextView);

String source = "這只是一個測試,測試<u>下劃線</u>、<i>斜體字</i>、<font color='blue'>藍色字</font>的格式";

htmlFormateTextView.setText(Html.fromHtml(source));

④ 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);

⑤ android,在線性布局中如何改變裡面所有textView的文字顏色呢要用到函數嗎

1、自定義TextView並改變字體顏色,把xml布局裡面的全替換成你這個;
2、在代碼界面,通過查找子View來遍歷,如果子view是TextView則改字體顏色

⑥ android 中的textview中 設置字的顏色,失效只有第一個可以顯示出來顏色,其他的都是系統默認的

其他是否處於不可用狀態,察看一下代碼中是否設置了setEnabled(false)

⑦ 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 listview的item被點擊時,如何改變item裡面的textview的文字顏色

parent.getChildAt(position).

這個方法應該是可行的。

View v=parent.getChildAt(position);
v.setTextColor();

如果不行,先這樣

for(int i=0;i<parent.getCount();i++){
View w=parent.getChildAt(i);
w.setTextColor(別的color);
}



View v=parent.getChildAt(position);
v.setTextColor();

這樣試試吧。

⑨ 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 studio 怎麼設置textview的字體顏色為黑色

<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="西堤牛排" android:id="@+id/top" android:textSize="40dip"(大小) android:textColor="#000000"(顏色) />

閱讀全文

與androidtextview文字顏色相關的資料

熱點內容
自己購買雲主伺服器推薦 瀏覽:419
個人所得稅java 瀏覽:761
多餘的伺服器滑道還有什麼用 瀏覽:189
pdf劈開合並 瀏覽:27
不能修改的pdf 瀏覽:751
同城公眾源碼 瀏覽:488
一個伺服器2個埠怎麼映射 瀏覽:297
java字元串ascii碼 瀏覽:78
台灣雲伺服器怎麼租伺服器 瀏覽:475
旅遊手機網站源碼 瀏覽:332
android關聯表 瀏覽:945
安卓導航無聲音怎麼維修 瀏覽:332
app怎麼裝視頻 瀏覽:430
安卓系統下的軟體怎麼移到桌面 瀏覽:96
windows拷貝到linux 瀏覽:772
mdr軟體解壓和別人不一樣 瀏覽:904
單片機串列通信有什麼好處 瀏覽:340
游戲開發程序員書籍 瀏覽:860
pdf中圖片修改 瀏覽:288
匯編編譯後 瀏覽:491