Skip to content

Instantly share code, notes, and snippets.

@akmalxxx
Created January 28, 2015 03:13
Show Gist options
  • Save akmalxxx/ce5b6e13195bcace3ba7 to your computer and use it in GitHub Desktop.
Save akmalxxx/ce5b6e13195bcace3ba7 to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.EditText;
import android.os.Build;
import android.support.v7.internal.widget.TintTypedArray;
public class EditTextEx extends EditText {
private static final int[] TINT_ATTRS = { android.R.attr.background };
public EditTextEx(Context context) { super(context); init(context, null); }
public EditTextEx(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); }
public EditTextEx(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context, attrs); }
private void init(Context context, AttributeSet attrs) {
//custom font
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Custom);
setTypeface(FontUtil.getTypeface(a.getInt(R.styleable.Custom_typeface, FontUtil.ROBOTO_REGULAR)));
a.recycle();
//material
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
TintTypedArray ta = TintTypedArray.obtainStyledAttributes(context, attrs, TINT_ATTRS, android.R.attr.editTextStyle, 0);
setBackgroundDrawable(ta.getDrawable(0));
ta.recycle();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment