1. 自選顏色最快的方法:
setBackgroundColor(Color.parseColor("#636161"));
textview1.setTextColor(Color.rgb((int)2F, 00, 00));
textview1.setTextColor(Color.rgb((int)2F, 00, 00));
2. 系統的方法:
tv.setTextColor(android.graphics.Color.RED);/
3. 靜態改變顯示顏色的方法:
建立:res/values/color.xml, 編輯會用到的顏色如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#FF0000</color>
<color name="cyan">#00FFFF</color>
<color name="blue">#0000FF</color>
<color name="darkBlue">#0000A0</color>
<color name="lightBlue">#ADD8E6</color>
<color name="purple">#800080</color>
<color name="yellow">#FFFF00</color>
<color name="lime">#00FF00</color>
<color name="fuchsia">#FF00FF</color>
<color name="white">#FFFFFF</color>
<color name="silver">#C0C0C0</color>
<color name="gray">#808080</color>
<color name="black">#000000</color>
<color name="orange">#FFA500</color>
<color name="brown">#A52A2A</color>
<color name="maroon">#800000</color>
<color name="green">#008000</color>
<color name="olive">#808000</color>
<color name="light_purple">#8A0868</color><color name="pink">#DF01D7</color>
<color name="pink_light01">#F6CEF5</color>
<color name="green_light01">#BCF5A9</color>
</resources>
android:textColor="@android:color/white"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/purple"> <!-- 改變背景色 -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="我是黃色 "
android:textColor="@color/yellow" <!-- 改變文字欄位顏色 -->
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="我是亮綠色 "
android:textColor="@color/lime" <!-- 改變文字欄位顏色 -->
/>
</LinearLayout>
5. 有了 res/values/color.xml
也可以在程式裡打上:
tv.setTextColor(R.color.blue);
沒有留言:
張貼留言