Skip to content

Instantly share code, notes, and snippets.

@MichaelRocks
Forked from jimmyjjames/AndroidManifest.xml
Created January 9, 2012 15:14
Show Gist options
  • Save MichaelRocks/1583346 to your computer and use it in GitHub Desktop.
Save MichaelRocks/1583346 to your computer and use it in GitHub Desktop.
Android Theming Test
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.theming"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="11" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".ThemingTesterActivity"
android:theme="@style/Theme.Custom"
>
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomImageButton">
<attr name="customAttr" format="string"/>
</declare-styleable>
<declare-styleable name="CustomTheme">
<attr name="customImageButtonStyle" format="reference"/>
</declare-styleable>
</resources>
package com.example.theming;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageButton;
public class CustomImageButton extends ImageButton {
private String customAttr;
public CustomImageButton(Context context) {
this(context, null);
}
public CustomImageButton(Context context, AttributeSet attrs) {
this( context, attrs, R.styleable.CustomTheme_customImageButtonStyle );
}
public CustomImageButton(Context context, AttributeSet attrs, int defStyle) {
super( context, attrs, defStyle );
final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CustomImageButton, defStyle, R.style.Widget_ImageButton_Custom );
this.customAttr = array.getString(R.styleable.CustomImageButton_customeAttr);
array.recycle();
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Widget.ImageButton.Custom" parent="android:style/Widget.ImageButton">
<item name="customAttr">some value</item>
<item name="android:background">#ff00ff00</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Custom" parent="@android:style/Theme">
<item name="customImageButtonStyle">@style/Widget.ImageButton.Custom</item>
</style>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment