Modify /res/values/strings.xml, add a new style "MyStyle.GreenBold" inherit properties from "MyStyle", change and add properties of "android:textColor" and "android:textStyle".
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#AAA</item>
<item name="android:textSize">18dip</item>
<item name="android:background">#222</item>
<item name="android:padding">5dip</item>
</style>
<style name="MyStyle.GreenBold">
<item name="android:textColor">#00FF00</item>
<item name="android:textStyle">bold</item>
</style>
</resources>
Modify main.xml adding TextView using new style of "MyStyle.GreenBold".
<?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
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TextView
style="@style/MyStyle"
android:layout_width="fill_parent"
android:text="it's text using style" />
<TextView
style="@style/MyStyle.GreenBold"
android:layout_width="fill_parent"
android:text="it's text using style of MyStyle.GreenBold" />
</LinearLayout>
![Create style inheriting properties from another style Create style inheriting properties from another style](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5y3VSCxvMJsOxHwtdVQSoBGa_HRNNmo23cu9t7YVTj9EV4R7WSxZbWu-sc9406UjIMvcM_7nFUmmsMTY4g6p5lHySmj44DmM4YVifnZ7iXEQDifZuKC7ijg5jzV-kzHNBZJ0x2xUUlMku/s400/AndroidStyle_02.png)
next:
- Apply style on whole application/activity as theme
No comments:
Post a Comment