Last active
August 29, 2015 14:02
-
-
Save laaptu/ba5fb40547742ca125f3 to your computer and use it in GitHub Desktop.
How to apply themes to the Custom Views in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<declare-styleable name="BaseEditTextTheme"> | |
<attr name="baseEditTextStyle" format="reference" /> | |
</declare-styleable> | |
And finally in my themes.xml file | |
<item name="baseEditTextStyle">@style/EditTextfs</item> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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