- Create style using Android Resources Tools
- Create style inheriting properties from another style
- Apply style on whole application/activity as theme
- Using Android build-in theme
We can create our custom Theme, by inheriting properties from build-in Theme.
Create(or modify from previous post) /res/values/mystyle.xml, create our custom style (MyStyle) from build-in "@android:style/Theme.Dialog".
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyStyle"
parent="@android:style/Theme.Dialog">
<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 AndroidManifest.xml using theme of our custom style, "@style/MyStyle.GreenBold".
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.AndroidStyle"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MyStyle.GreenBold" >
<activity
android:name=".AndroidStyleActivity"
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>
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
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="using Style inherit from Android's build-in theme" />
</LinearLayout>
0 Response to "Create custom Theme inheriting properties from build-in Theme"
Posting Komentar