这个示例通过在Manifest中设置主题,从而使Activity中的布局实现主题中设置的各类属性。
[img]http://dl.iteye.com/upload/attachment/507986/264aac3b-f797-386b-aee2-67aef253924b.jpg[/img]
这个是在Manifest中定义主题的方式,通过设置Manifest中<activity>标签的android:theme属性,调用设置在res/styles文件夹中的Style,android也自带了许多style供开发者使用。style的设置和调用方便了View和ViewGroup的设置,很容易实现复用。
<style>标签的parent属性可以实现对已经设置好的style进行继承,并可以嵌套任意个<item>用于指定View或者ViewGroup中某属性以及该属性的值。
Shape保存与res/drawable文件夹中,<shape>标签用于定义控件的显示属性,通过在<style>中嵌套<gradient>(渐变),<solid>(填充),<stroke>(描边),<corners>(圆角),<padding>
<solid android:color="#f0600000"/>定义了填充的颜色。
<stroke android:width="3dp" color="#ffff8080"/>定义了描边的宽度和颜色。
<corners android:radius="3dp" />定义了控件圆角的半径。
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />定义了控件中内容的缩进
[img]http://dl.iteye.com/upload/attachment/507986/264aac3b-f797-386b-aee2-67aef253924b.jpg[/img]
android:theme="@android:style/Theme.Dialog"
这个是在Manifest中定义主题的方式,通过设置Manifest中<activity>标签的android:theme属性,调用设置在res/styles文件夹中的Style,android也自带了许多style供开发者使用。style的设置和调用方便了View和ViewGroup的设置,很容易实现复用。
<style name="Theme.CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@drawable/filled_box</item>
</style>
<style>标签的parent属性可以实现对已经设置好的style进行继承,并可以嵌套任意个<item>用于指定View或者ViewGroup中某属性以及该属性的值。
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#f0600000"/>
<stroke android:width="3dp" color="#ffff8080"/>
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
Shape保存与res/drawable文件夹中,<shape>标签用于定义控件的显示属性,通过在<style>中嵌套<gradient>(渐变),<solid>(填充),<stroke>(描边),<corners>(圆角),<padding>
<solid android:color="#f0600000"/>定义了填充的颜色。
<stroke android:width="3dp" color="#ffff8080"/>定义了描边的宽度和颜色。
<corners android:radius="3dp" />定义了控件圆角的半径。
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />定义了控件中内容的缩进