Android中的自定义主题和样式
Android中的自定义主题和样式
Android中的自定义主题和样式
效果如下图:
通过xml文件来设置主题和样式:
style文件自定义样式和主题的代码:
<?xml version="1.0" encoding="utf-8"?>
<resources>
//设置父主题,取自TextAppearance
<style name="tmacskyTheme" parent="@android:style/TextAppearance">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
</style>
//设置子主题
<style name="tmacskyTheme.textRed">
<item name="android:background">@color/red</item>
</style>
<style name="tmacskyTheme.textBlue">
<item name="android:background">@color/blue</item>
</style>
<style name="tmacskyTheme.textGreen">
<item name="android:background">@color/green</item>
</style>
//设置颜色
<color name="red">#FF0000</color>
<color name="green">#00FF00</color>
<color name="blue">#0000FF</color>
</resources>
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
style="@style/tmacskyTheme.textBlue"
android:text="TextView1" />
<TextView
android:id="@+id/textView2"
style="@style/tmacskyTheme.textGreen"
android:text="TextView2" />
<TextView
style="@style/tmacskyTheme.textRed"
android:id="@+id/textView3"
android:text="TextView3" />
</LinearLayout>
Android应用开发之样式
Android--ListView滚动条样式
Android使用自定义透明Dialog样式的Activity
评论暂时关闭