爲android的view組件指定樣式

當android程序需要統一的界面樣式或者是多人開發,可以使用爲View的組件指定樣式,具體如下:

指定步驟:

1.定義用於保存樣式的xml文件,res/values/style.xml。

2.在res/values/style.xml文件中寫入如下的一些xml標籤內容:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <style name="styleText1">
  <item name="android:textSize">18sp</item>
  <item name="android:textColor">#ec9237</item>
 </style>
 <style name="styleText2">
  <item name="android:textSize">14sp</item>
  <item name="android:textColor">#ff7f7c</item>
  <item name="android:fromAlpha">0.0</item>
  <item name="android:toAlpha">0.0</item>
 </style>
</resources>

3.爲組件指定樣式,如下:

<TextView style="@style/styleText1" android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:text="@string/text_value1"
  android:gravity="center_vertical|center_horizontal" />

 <TextView style="@style/styleText2" android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:text="@string/text_value2"
  android:gravity="center_vertical|center_horizontal" />

4.查看效果,如下:

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章