歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android中的自定義主題和樣式

Android中的自定義主題和樣式

日期:2017/3/1 9:55:14   编辑:Linux編程

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"

android:text="TextView1" />
<TextView
android:id="@+id/textView2"

android:text="TextView2" />
<TextView

android:id="@+id/textView3"
android:text="TextView3" />
</LinearLayout>

Copyright © Linux教程網 All Rights Reserved