您的位置:首页 > 移动开发 > Android开发

Android 主题和样式

2016-04-24 18:46 295 查看
一、样式是属性的集合,以独立的资源文件存放在XML中,并设置样式的名称,可以让设计与内容分离,并且可以方便的继承,覆盖,重用。

1、Style使用 ,在res/values/下创建Style XML资源文件,这里创建的Style资源文件名命名为styles.xml,这个可以自己自定义。

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="wrap_content">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>


2、样式的继承, 两种方法,一种是通过style的parent属性,二是使用类似css中的命名规则来实现

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="wrap_content">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>

<style name="inherit" parent="wrap_content">
<item name="android:textColor">#00FF00</item>
</style>
</resources>


<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="wrap_content">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>

<style name="wrap_content.inherit">
<item name="android:textColor">#00FF00</item>
</style>
</resources>


二、主题,针对应用中所有act或者针对某个act设置样式。通过编辑配置文件来完成

1、针对所有act

<application android:theme="@style/wrap_content">


2、针对某个指定act

<activity android:theme="@style/wrap_content">
3、android提供了许多自带的主题样式。例如Theme.Dialog、Theme.Translucent等等。使用方式也很简单

<activity android:theme="@android:style/Theme.Dialog">
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: