Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ParkSangGwon
Last active March 8, 2016 14:19
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 ParkSangGwon/6ab6677f74b22b0b9505 to your computer and use it in GitHub Desktop.
Save ParkSangGwon/6ab6677f74b22b0b9505 to your computer and use it in GitHub Desktop.
public class CustomLoginButton extends LinearLayout {
LinearLayout bg;
ImageView symbol;
TextView text;
public CustomLoginButton(Context context) {
super(context);
initView();
}
public CustomLoginButton(Context context, AttributeSet attrs) {
super(context, attrs);
initView();
getAttrs(attrs);
}
public CustomLoginButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs);
initView();
getAttrs(attrs, defStyle);
}
private void initView() {
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater) getContext().getSystemService(infService);
View v = li.inflate(R.layout.welcome_login_button, this, false);
addView(v);
bg = (LinearLayout) findViewById(R.id.bg);
symbol = (ImageView) findViewById(R.id.symbol);
text = (TextView) findViewById(R.id.text);
}
private void getAttrs(AttributeSet attrs) {
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.LoginButton);
setTypeArray(typedArray);
}
private void getAttrs(AttributeSet attrs, int defStyle) {
TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.LoginButton, defStyle, 0);
setTypeArray(typedArray);
}
private void setTypeArray(TypedArray typedArray) {
int bg_resID = typedArray.getResourceId(R.styleable.LoginButton_bg, R.drawable.login_naver_bg);
bg.setBackgroundResource(bg_resID);
int symbol_resID = typedArray.getResourceId(R.styleable.LoginButton_symbol, R.drawable.login_naver_symbol);
symbol.setImageResource(symbol_resID);
int textColor = typedArray.getColor(R.styleable.LoginButton_textColor, 0);
text.setTextColor(textColor);
String text_string = typedArray.getString(R.styleable.LoginButton_text);
text.setText(text_string);
typedArray.recycle();
}
void setBg(int bg_resID) {
bg.setBackgroundResource(bg_resID);
}
void setSymbol(int symbol_resID) {
symbol.setImageResource(symbol_resID);
}
void setTextColor(int color) {
text.setTextColor(color);
}
void setText(String text_string) {
text.setText(text_string);
}
void setText(int text_resID) {
text.setText(text_resID);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment