Apply style on whole application/activity as theme

The custome style create in last posts Create style using Android Resources Tools and Create style inheriting properties from another style can be apply on whole application/activity as theme.

Apply style on whole application/activity as theme

Modify AndroidManifest.xml to add android:theme="@style/MyStyle.GreenBold" property inside <application> to apply the style as theme on whole application, or inside <activity> to apply on individual activity only.
<?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>


Modify main.xml, change TextView using application/activity theme.
<?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:text="Default, using style of MyStyle.GreenBold defined in AndroidManifest.xml" />

</LinearLayout>


Related:
- Using Android build-in theme

0 Response to "Apply style on whole application/activity as theme"

Posting Komentar