1、main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
style="@style/TextViewStyle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textview1" />
<TextView
style="@style/TextViewStyle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/textview2" />
</LinearLayout>
2、style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="TextViewStyle1">
<item name="android:textColor">#ffff0000</item>
<item name="android:textSize">36sp</item>>
</style>
<style name="TextViewStyle2">
<item name="android:textColor">#ff00ff00</item>
<item name="android:textSize">24sp</item>>
<item name="android:textStyle">italic</item>
</style>
</resources>
3、java代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
4、运行结果: