Created
April 17, 2016 14:07
-
-
Save Palatis/7e7955cc82a4dcbd1b941d011fbdaeda to your computer and use it in GitHub Desktop.
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 MyCustomView extends View { | |
public MyCustomView(Context context) { this(context, R.style.MyCustomView); } | |
public MyCustomView(Context context, AttributeSet attrs) { this(context, attrs, 0); } | |
public MyCustomView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
final int defStyleRes = 0; | |
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyCustomView, defStyle, defStyleRes); | |
try { | |
this.search_width = a.getDimension(R.styleable.MyCustomView_search_width, 123); // a fallback default value... | |
this.search_height = a.getDimension(R.styleable.MyCustomView_search_height, 456); | |
/* ... i'm lazy to type the rest...... */ | |
} finally { | |
/* call recycle() after you're done. */ | |
a.recycle(); | |
} | |
} | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<style name="MyCustomView"> | |
<item name="search_width">300dp</item> | |
<item name="search_height">50dp</item> | |
<item name="f1_column_width">25dp</item> | |
<item name="f3_column_width">280dp</item> | |
<item name="f4_column_width">45dp</item> | |
<item name="edittext_height">30dp</item> | |
</declare-styleable> | |
</resources> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<!-- the name doesn't have to be the same as the class name of your | |
custom view, but we usually use the same name to avoid obfuscation. --> | |
<declare-styleable name="MyCustomView"> | |
<attr name="search_width" format="dimension"/> | |
<attr name="search_height" format="dimension"/> | |
<attr name="f1_column_width" format="dimension"/> | |
<attr name="f3_column_width" format="dimension"/> | |
<attr name="f4_column_width" format="dimension"/> | |
<attr name="edittext_height" format="dimension"/> | |
</declare-styleable> | |
</resources> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<style name="MyCustomView"> | |
<item name="search_width">150dp</item> | |
<item name="search_height">50dp</item> | |
<item name="f1_column_width">25dp</item> | |
<item name="f3_column_width">140dp</item> | |
<item name="f4_column_width">45dp</item> | |
<item name="edittext_height">30dp</item> | |
</declare-styleable> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment