Skip to content

Instantly share code, notes, and snippets.

@jimmyjjames
Created November 24, 2011 17:33
Show Gist options
  • Save jimmyjjames/1391862 to your computer and use it in GitHub Desktop.
Save jimmyjjames/1391862 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="customeAttr" 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
xmlns:custom="http://schemas.android.com/apk/res/com.example.theming"
>
<style name="Widget.ImageButton.Custom" parent="android:style/Widget.ImageButton">
<!--
<item name="custom:customAttr">some value</item>
-->
<item name="customAttr">some value</item>
<item name="android:background">#ff00ff00</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:custom="http://schemas.android.com/apk/res/com.example.theming"
>
<style name="Theme.Custom" parent="@android:style/Theme">
<!--
<item name="custom:customImageButtonStyle">@custom:style/Widget_ImageButton_Custom</item>
-->
<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