样式文件格式如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="样式文件名" parent="父样式表">
<item name="定义的属性">属性值</item>
</style>
</resources>
要使用已有的样式文件,在xml中相应的控件下添加属性如下:
style="@style/样式文件名"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
下面给一个简单TextView变超链接的Demo,部分相关代码.
在src/main/res/values/styles.xml中添加新的样式文件格式,源码如下所示:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="demo_style">
<item name="android:textSize" >30sp</item>
<item name="android:textColor">#FFFF00</item>
<item name="android:autoLink">web</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>
在src/main/res/layout/activity_main.xml中使用新添加的样式:
<TextView
android:id="@+id/tv_show"
style="@style/demo_style"
android:text="百度:http://www.baidu.com"
/>
如此操作之后,待你启动apk时候,就可以看到你的TextView控件已经按照指定的style样式显示了。
---- The End.