最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程實(shí)現(xiàn)TextView字體顏色設(shè)置的方法小結(jié)

 更新時(shí)間:2015年12月01日 14:44:19   作者:fengyee_zju  
這篇文章主要介紹了Android編程實(shí)現(xiàn)TextView字體顏色設(shè)置的方法,結(jié)合實(shí)例形式總結(jié)分析了Android針對(duì)TextView字體顏色設(shè)置的相關(guān)步驟與注意事項(xiàng),具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android編程實(shí)現(xiàn)TextView字體顏色設(shè)置的方法。分享給大家供大家參考,具體如下:

對(duì)于setTextView(int a)這里的a是傳進(jìn)去顏色的值。例如,紅色0xff0000是指0xff0000如何直接傳入R.color.red是沒有辦法設(shè)置顏色的,只有通過(guò)文章中的第三種方法先拿到資源的顏色值再傳進(jìn)去。

復(fù)制代碼 代碼如下:
tv.setTextColor(this.getResources().getColor(R.color.red));

關(guān)鍵字: android textview color

TextView的字體設(shè)置方法:

1、直接通過(guò)配置文件設(shè)置

2、在Activity類中進(jìn)行設(shè)置

第一種方式很簡(jiǎn)單,用于靜態(tài)或初始文字顏色的設(shè)置,方法如下:

main.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 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 version="1.0" encoding="utf-8"?> 
<resources> 
 <string name="hello">地址:http://www.fzitv.net/</string> 
  <string name="app_name">腳本之家</string> 
</resources>

上面將資源部分分成了3個(gè)部分,目的是為了清晰,當(dāng)然你也可以只建一個(gè)xml文件放在res目錄下,而且文件名稱可以隨便命名。

注意兩個(gè)地方:

1、main.xml的TextView標(biāo)簽中:

復(fù)制代碼 代碼如下:
android:textColor="@color/red"

2、color.xml中:
復(fù)制代碼 代碼如下:
<color name="red">#FF0000</color>

@color指獲取資源文件中(所有res目錄下的xml文件)的<color>標(biāo)簽

/red指在標(biāo)簽下找其name值為red的內(nèi)容,此時(shí)其值為#FF0000

因此,這里我們還可以這樣做:

復(fù)制代碼 代碼如下:
android:textColor="@drawable/red"

@drawable指獲取資源文件中<drawable>標(biāo)簽

/red指在標(biāo)簽下找其name值為red的內(nèi)容

以此類推,相信你也就知道了如果是在strings.xml中該怎么做了。

下面看看第二種方式:在Activity類中進(jìn)行設(shè)置

1、先將main.xml改成如下,即去掉android:textColor="@color/red":

<?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,原始代碼如下:

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

第二步:通過(guò)TextView的setTextColor方法進(jìn)行文本顏色的設(shè)置,這里可以有3種方式進(jìn)行設(shè)置:

第1種:

復(fù)制代碼 代碼如下:
tv.setTextColor(android.graphics.Color.RED);//系統(tǒng)自帶的顏色類

第2種:
復(fù)制代碼 代碼如下:
tv.setTextColor(0xffff00ff);//0xffff00ff是int類型的數(shù)據(jù)
分組一下0x|ff|ff00ff,0x是代表顏色整數(shù)的標(biāo)記,ff是表示透明度,ff00ff表示顏色,注意:這里ffff00ff必須是8個(gè)的顏色表示,不接受ff00ff這種6個(gè)的顏色表示。

第3種:

復(fù)制代碼 代碼如下:
tv.setTextColor(this.getResources().getColor(R.color.red));//通過(guò)獲得資源文件進(jìn)行設(shè)置。
根據(jù)不同的情況R.color.red也可以是R.string.red或者R.drawable.red,當(dāng)然前提是需要在相應(yīng)的配置文件里做相應(yīng)的配置,如:

<color name="red">#FF0000</color>
<drawable name="red">#FF0000</drawable>
<string name="red">#FF0000</string>

詳細(xì)的代碼如下:

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

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android自定義Animation實(shí)現(xiàn)View搖擺效果

    Android自定義Animation實(shí)現(xiàn)View搖擺效果

    這篇文章主要為大家詳細(xì)介紹了Android自定義Animation實(shí)現(xiàn)View搖擺效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • Android實(shí)現(xiàn)NFC讀取校園卡

    Android實(shí)現(xiàn)NFC讀取校園卡

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)NFC讀取校園卡,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Android View的事件分發(fā)詳解

    Android View的事件分發(fā)詳解

    我們?cè)趯W(xué)習(xí)View的時(shí)候,不可避免會(huì)遇到事件的分發(fā),而往往遇到的很多滑動(dòng)沖突的問(wèn)題都是由于處理事件分發(fā)時(shí)不恰當(dāng)所造成的。因此,深入了解View事件分發(fā)機(jī)制的原理,對(duì)于我們來(lái)說(shuō)是很有必要的。
    2017-12-12
  • 深入分析Android NFC技術(shù) android nfc開發(fā)

    深入分析Android NFC技術(shù) android nfc開發(fā)

    本篇文章我們對(duì)android開發(fā)中nfc技術(shù)做了全面的原理分析以及實(shí)現(xiàn)過(guò)程,需要的讀者們一起參考一下吧。
    2017-11-11
  • Android星級(jí)評(píng)分條控件RatingBar使用詳解

    Android星級(jí)評(píng)分條控件RatingBar使用詳解

    這篇文章主要為大家詳細(xì)介紹了Android星級(jí)評(píng)分條控件RatingBar的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • Android自定義View實(shí)現(xiàn)角度選擇器

    Android自定義View實(shí)現(xiàn)角度選擇器

    前幾天在Google Photos查看照片,用了一下它的圖片剪裁功能,于是我馬上就被其界面和操作吸引。后來(lái)想模仿做一個(gè)和Google Photos裁圖頁(yè)面幾乎一模一樣的角度選擇器,本文比較基礎(chǔ),在閱讀本文前只需要掌握最基礎(chǔ)的自定義View知識(shí)和Android事件知識(shí)。下面來(lái)一起學(xué)習(xí)下吧。
    2016-11-11
  • Android改變ExpandableListView的indicator圖標(biāo)實(shí)現(xiàn)方法

    Android改變ExpandableListView的indicator圖標(biāo)實(shí)現(xiàn)方法

    這篇文章主要介紹了Android改變ExpandableListView的indicator圖標(biāo)實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了改變ExpandableListView的indicator圖標(biāo)相關(guān)步驟與實(shí)現(xiàn)技巧,涉及Android配置文件的修改,需要的朋友可以參考下
    2016-03-03
  • Android ActionBar完全解析使用官方推薦的最佳導(dǎo)航欄(上)

    Android ActionBar完全解析使用官方推薦的最佳導(dǎo)航欄(上)

    Action Bar是一種新増的導(dǎo)航欄功能,在Android 3.0之后加入到系統(tǒng)的API當(dāng)中,它標(biāo)識(shí)了用戶當(dāng)前操作界面的位置,并提供了額外的用戶動(dòng)作、界面導(dǎo)航等功能
    2017-04-04
  • Windows下快速搭建安卓開發(fā)環(huán)境Android studio

    Windows下快速搭建安卓開發(fā)環(huán)境Android studio

    這篇文章主要介紹了Windows下快速搭建安卓開發(fā)環(huán)境Android studio的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-07-07
  • Android編程中沉浸式狀態(tài)欄的三種實(shí)現(xiàn)方式詳解

    Android編程中沉浸式狀態(tài)欄的三種實(shí)現(xiàn)方式詳解

    這篇文章主要介紹了Android編程中沉浸式狀態(tài)欄的三種實(shí)現(xiàn)方式,簡(jiǎn)單描述了沉浸式狀態(tài)欄的概念、功能并結(jié)合實(shí)例形式詳細(xì)分析了Android實(shí)現(xiàn)沉浸式狀態(tài)欄的三種操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2018-02-02

最新評(píng)論

株洲市| 张家口市| 霍山县| 胶州市| 娄底市| 广河县| 梨树县| 南靖县| 疏勒县| 景东| 马鞍山市| 利津县| 大荔县| 安龙县| 阳春市| 安达市| 齐河县| 兴文县| 台前县| 清徐县| 桂阳县| 博野县| 绿春县| 绩溪县| 泾阳县| 即墨市| 双柏县| 怀安县| 岗巴县| 定远县| 罗江县| 莎车县| 闻喜县| 永修县| 元阳县| 桃园县| 宜黄县| 屏南县| 富裕县| 金秀| 从江县|