在res/values目录下创建style.xml文件。在声明时先要声明xml的版本及encoding编码为UTF-8,其内的resources需要以stylename作为样式名称,最内层才是item定义样式的范围,语法如下:
<resources>
<style name=string>
<item name=string>Hex value | string value | reference </item>
</style>
</resources>
可能有点抽象,直接给个例子就明白了。
绑定到具体的控件,是通过控件的style属性来绑定的,如下:
<resources>
<style name=string>
<item name=string>Hex value | string value | reference </item>
</style>
</resources>
可能有点抽象,直接给个例子就明白了。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="textview1">
<item name="android:textSize">18sp</item>
<item name="android:textColor">#EC9237</item>
</style>
<style name="textview2">
<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>
绑定到具体的控件,是通过控件的style属性来绑定的,如下:
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView android:text="TextView1"
style="@style/textview1"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:text="TextView2"
style="@style/textview2"
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>