下面列出了android.widget.RadioButton#setClickable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void createRadioButtons() {
// set button dimension
int buttonSize = AptoideUtils.ScreenU.getPixelsForDip(10, getResources());
ViewGroup.LayoutParams buttonLayoutParams = new RadioGroup.LayoutParams(buttonSize, buttonSize);
// set button margin
int buttonMargin = AptoideUtils.ScreenU.getPixelsForDip(2, getResources());
ViewGroup.MarginLayoutParams marginLayoutParams =
(ViewGroup.MarginLayoutParams) buttonLayoutParams;
marginLayoutParams.setMargins(buttonMargin, buttonMargin, buttonMargin, buttonMargin);
final int pages = viewPagerAdapter.getCount();
wizardButtons = new ArrayList<>(pages);
Context context = getContext();
for (int i = 0; i < pages; i++) {
RadioButton radioButton = new RadioButton(context);
radioButton.setLayoutParams(buttonLayoutParams);
radioButton.setButtonDrawable(android.R.color.transparent);
radioButton.setBackgroundResource(R.drawable.wizard_custom_indicator);
radioButton.setClickable(false);
radioGroup.addView(radioButton);
wizardButtons.add(radioButton);
}
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
removeAllViews();
for (int i = 0; i < pageCount; i++) {
RadioButton rb = new RadioButton(getContext());
rb.setFocusable(false);
rb.setClickable(false);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
Drawable d = ContextCompat.getDrawable(getContext(), R.drawable.indicator);
rb.setButtonDrawable(d);
LinearLayout.LayoutParams params = generateDefaultLayoutParams();
params.width = d.getIntrinsicWidth();
params.height = d.getIntrinsicHeight();
rb.setLayoutParams(params);
} else {
rb.setButtonDrawable(R.drawable.indicator);
}
addView(rb);
}
setCurrentPosition(-1);
}
private void setStreamButtonEnableByLevel(int level) {
boolean z;
boolean z2 = true;
this.mLowButton.setClickable(level != 0);
RadioButton radioButton = this.mStandardButton;
if (level != 1) {
z = true;
} else {
z = false;
}
radioButton.setClickable(z);
radioButton = this.mHighButton;
if (level != 2) {
z = true;
} else {
z = false;
}
radioButton.setClickable(z);
radioButton = this.mSuperHighButton;
if (level != 3) {
z = true;
} else {
z = false;
}
radioButton.setClickable(z);
radioButton = this.m720Button;
if (level != 4) {
z = true;
} else {
z = false;
}
radioButton.setClickable(z);
RadioButton radioButton2 = this.m1080Button;
if (level == 5) {
z2 = false;
}
radioButton2.setClickable(z2);
}
/**
* Constructor for inflating via XML.
*/
public RadioButtonWithDescription(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.radio_button_with_description, this, true);
mRadioButton = (RadioButton) findViewById(R.id.radio_button);
mTitle = (TextView) findViewById(R.id.title);
mDescription = (TextView) findViewById(R.id.description);
if (attrs != null) applyAttributes(attrs);
// We want RadioButtonWithDescription to handle the clicks itself.
mRadioButton.setClickable(false);
setOnClickListener(this);
}
/**
* Constructor for inflating via XML.
*/
public RadioButtonWithDescription(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.radio_button_with_description, this, true);
mRadioButton = (RadioButton) findViewById(R.id.radio_button);
mTitle = (TextView) findViewById(R.id.title);
mDescription = (TextView) findViewById(R.id.description);
if (attrs != null) applyAttributes(attrs);
// We want RadioButtonWithDescription to handle the clicks itself.
mRadioButton.setClickable(false);
setOnClickListener(this);
}
/**
* Constructor for inflating via XML.
*/
public RadioButtonWithDescription(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.radio_button_with_description, this, true);
mRadioButton = (RadioButton) findViewById(R.id.radio_button);
mTitle = (TextView) findViewById(R.id.title);
mDescription = (TextView) findViewById(R.id.description);
if (attrs != null) applyAttributes(attrs);
// We want RadioButtonWithDescription to handle the clicks itself.
mRadioButton.setClickable(false);
setOnClickListener(this);
}
private void showIconDialog() {
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogLayout = inflater.inflate(R.layout.dialog_icon, (ViewGroup) getActivity().findViewById(R.id.dialog_root));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setView(dialogLayout);
final AlertDialog alertDialog = builder.create();
LinearLayout layoutTypeOne = (LinearLayout) dialogLayout.findViewById(R.id.layout_one);
layoutTypeOne.setClickable(true);
RadioButton radioTypeOne = (RadioButton) dialogLayout.findViewById(R.id.radio_one);
LinearLayout layoutTypeTwo = (LinearLayout) dialogLayout.findViewById(R.id.layout_two);
layoutTypeTwo.setClickable(true);
RadioButton radioTypeTwo = (RadioButton) dialogLayout.findViewById(R.id.radio_two);
TextView done = (TextView) dialogLayout.findViewById(R.id.done);
radioTypeOne.setClickable(false);
radioTypeTwo.setClickable(false);
alertDialog.show();
switch (mSharedPreferenceUtil.getIconType()) {
case 0:
radioTypeOne.setChecked(true);
radioTypeTwo.setChecked(false);
break;
case 1:
radioTypeOne.setChecked(false);
radioTypeTwo.setChecked(true);
break;
}
layoutTypeOne.setOnClickListener(v -> {
radioTypeOne.setChecked(true);
radioTypeTwo.setChecked(false);
});
layoutTypeTwo.setOnClickListener(v -> {
radioTypeOne.setChecked(false);
radioTypeTwo.setChecked(true);
});
done.setOnClickListener(v -> {
mSharedPreferenceUtil.setIconType(radioTypeOne.isChecked() ? 0 : 1);
String[] iconsText = getResources().getStringArray(R.array.icons);
mChangeIcons.setSummary(radioTypeOne.isChecked() ? iconsText[0] :
iconsText[1]);
alertDialog.dismiss();
Snackbar.make(getView(), "切换成功,重启应用生效",
Snackbar.LENGTH_INDEFINITE).setAction("重启",
v1 -> {
Intent intent = new Intent(getActivity(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
getActivity().finish();
RxBus.getDefault().post(new ChangeCityEvent());
}).show();
});
}