在應用中有自定義button。想修改一下顏色,不知道怎麼實現?
我的代碼:
public class CustomButton extends Button {
public CustomButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public CustomButton(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomButton(Context context) {
super(context);
init();
}
private void init() {
if (!isInEditMode()) {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "MyCustomFont.otf");
setTypeface(tf);
}
}
}
用setTextColor(Color.BLUE)
試試:
private void init() {
if (!isInEditMode()) {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "MyCustomFont.otf");
setTypeface(tf);
setTextColor(Color.BLUE);
}
}