样式:
定义组件样式的时候有两种定义方法:
1.直接在main.xml的组件中定义样式
2.用style="@style/"引用values文件夹下的样式文件里定义的样式
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
style="@style/style1"
android:text="hahahaha1" />
<TextView
style="@style/style2"
android:text="hahahaha2" />
<TextView
style="@style/style2.style1"
android:text="hahahaha4" />
<!-- 最基本的样式写法,直接写在组件里,和html标签中写style属性一个意思 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hahahaha3"
android:textSize="30sp"
android:textColor="#0000FF" />
</LinearLayout>
string,xml(也可以新建一个样式的xml文件,在里边定义样式)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, MainActivity!</string>
<string name="app_name">TestStyle</string>
<style name="style1">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">50sp</item>
</style>
<!-- 样式的继承 -->
<style name="style2" parent="style1">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#00FF00</item>
</style>
<!-- 样式的继承另一种写法 -->
<style name="style2.style1">
</style>
</resources>
主题:
主题就是清单文件中的android:theme属性,当这个属性在application组件中就是做用于所有Activity,当这个属性在某个Activity上,就表示对某个Activity有效。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxc.style"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<!-- android:theme也可以定义在application-->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!-- android:theme用来定义Activity样式的 -->
<activity
android:theme="@android:style/Theme.Dialog"
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>