I have an custom button, the state will changed when pressed to count down. I want to add the background under state. Here is my Java code:
RoundedColorDrawable bg_enable = new RoundedColorDrawable(0, 0xffe8b655);
bg_enable.setRadii(new float[]{0, 0, r, r, r, r, 0, 0});
bg_enable.setBorder(0xffe8b655, bw);
RoundedColorDrawable bg_disable = new RoundedColorDrawable(0, 0xffbcbcbc);
bg_disable.setRadii(new float[]{0, 0, r, r, r, r, 0, 0});
bg_disable.setBorder(0xffbcbcbc, bw);
StateListDrawable bg_btn = new StateListDrawable();
bg_btn.addState(new int[]{android.R.attr.enabled}, bg_enable);
bg_btn.addState(new int[]{}, bg_disable);
ViewUtils.setBackground(mBtnCode, bg_btn);
But the background is always bg_disable, the button is in android DialogFragment. I don't known why the enabled state not working.
Oh my god, it's my typing issue.
it's
android.R.attr.state_enabled
notandroid.R.attr.enabled