Skip to content

Instantly share code, notes, and snippets.

@laaptu
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laaptu/ba5fb40547742ca125f3 to your computer and use it in GitHub Desktop.
Save laaptu/ba5fb40547742ca125f3 to your computer and use it in GitHub Desktop.
How to apply themes to the Custom Views in Android
<declare-styleable name="BaseEditTextTheme">
<attr name="baseEditTextStyle" format="reference" />
</declare-styleable>
And finally in my themes.xml file
<item name="baseEditTextStyle">@style/EditTextfs</item>
public class BaseEditText extends EditText {
public BaseEditText(Context context) {
this(context, null);
}
public BaseEditText(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public BaseEditText(Context context, AttributeSet attrs, int defStyle) {
//super(context, attrs, defStyle);
super(context, attrs, R.attr.baseEditTextStyle);
init(context);
}
}
<!-- I have a custom style for all the edit text in my app -->
<item name="android:editTextStyle">@style/EditTextfs</item>
<style name="EditTextfs" parent="android:Widget.EditText">
<item name="android:background">@drawable/fs_edit_text_holo_light</item>
<item name="android:textColor">#000000</item>
<item name="android:singleLine">true</item>
</style>
<!-- So for my CustomEditText to use this theme directly I have to define attrs.xml-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment