我创建了一个自定义视图。我的自定义视图扩展自RelativeLayout:
public class CircleProgressButton extends RelativeLayout {...
在我的自定义视图中,我有一个按钮:
private void initView(Context context, AttributeSet attrs) {
TypedArray typedArray = context.getTheme().obtainStyledAttributes(
attrs, R.styleable.ProgressButton, 0, 0
);
try {
progressHeight = typedArray.getInt(R.styleable.ProgressButton_progress_height, progressHeight);
progressWidth = typedArray.getInt(R.styleable.ProgressButton_progress_width, progressWidth);
progressIconSuccess = typedArray.getResourceId(R.styleable.ProgressButton_progress_iconSuccess, R.drawable.ic_done);
progressIconFail = typedArray.getResourceId(R.styleable.ProgressButton_progress_iconfail, R.drawable.ic_fail);
progressText = typedArray.getString(R.styleable.ProgressButton_progress_text);
progressBackgroundImage = typedArray.getDrawable(R.styleable.ProgressButton_progress_button_background);
} finally {
typedArray.recycle();
}
initButton();
initProgressBar();
initImageView();
}
private void initButton() {
button = new AppCompatButton(getContext());
LayoutParams button_params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
button_params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
button.setLayoutParams(button_params);
button.setText(TextUtils.isEmpty(progressText) ? "Button" : progressText);
button.setGravity(Gravity.CENTER);
StateListDrawable background = new StateListDrawable();
background.addState(StateSet.WILD_CARD, progressBackgroundImage);
// background.addState(new int[]{android.R.attr.state_pressed}, progressBackgroundImagePressed);
button.setBackground(background);
button.setClickable(false);
}
30秒到达战场
绝地无双
相关分类