public class Controls_focus_click {
//按钮焦点
public static void Button(Button[] btn, Context context) {
for(Button s : btn) {
//焦点
s.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
btnBack(hasFocus, s, context);//状态
}
});
//点击
s.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, s.getText().toString(), Toast.LENGTH_LONG).show();
}
});
}
}
//按钮样式
public static void btnBack(Boolean tf, Button btn, Context context) {
if (tf) {
btn.setTextSize(16);
btn.setBackground(context.getResources().getDrawable(R.drawable.shape_radiobutton_p));
} else {
btn.setTextSize(14);
btn.setBackground(context.getResources().getDrawable(R.drawable.shape_radiobutton_n));
}
}
}
使用
Button [] btnarr = {btn_china,btn_english};
Controls_focus.Button(btnarr,mcontext);
|