樣式和主題(Style/Theme)
阿新 • • 發佈:2018-12-15
樣式:一般作用在控制元件上(button,textView等),樣式作用範圍比較窄。 主題:一般作用在activity或Application節點下,作用範圍比較大。 共同點:定義方式是一樣的。 樣式的應用
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:textColor="#0000ff" android:text="haha"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:textColor="#0000ff" android:text="heihei"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:textColor="#0000ff" android:text="hehe"/> </LinearLayout>
三個TextView中有大量重複的屬性,可以提取相同的屬性作為一個樣式。 在佈局中引用該樣式
主題的定義: 主題的應用: