本文介绍了如何使一个选项,褪色,但仍然可以点击在Android工作室?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个两个复选框,单击之一,当在哪里,对方会自动取消选中。我想保持这种但是有选中使人人成为褪色的白色,但仍然可以点击和可读性如果用户决定改变他/她的想法。

这是当前code我有:

  chk1.setOnCheckedChangeListener(新CompoundButton.OnCheckedChangeListener(){
        @覆盖
        公共无效onCheckedChanged(CompoundButton compoundButton,布尔B){
            如果(CheckBox.isChecked(CHK1)){
            chk2.setChecked(假);
            chk1.setChecked(二);
            chk2.setAlpha(0.5F);
        }
    });    chk2.setOnCheckedChangeListener(新CompoundButton.OnCheckedChangeListener(){
        @覆盖
        公共无效onCheckedChanged(CompoundButton compoundButton,布尔B){
            如果(CheckBox.isChecked(CHK2)){
            chk1.setChecked(假);
            chk2.setChecked(二);
            chk1.setAlpha(0.5F);
        }
    });


解决方案

chk2.setAlpha(0.5F)将使其出现褪色。

  chk1.setOnCheckedChangeListener(新CompoundButton.OnCheckedChangeListener(){
        @覆盖
        公共无效onCheckedChanged(CompoundButton compoundButton,布尔B){
            chk2.setChecked(假);
            chk1.setChecked(二);
            chk2.setAlpha(0.5F);
            chk1.setAlpha(1F);
        }
    });chk2.setOnCheckedChangeListener(新CompoundButton.OnCheckedChangeListener(){
    @覆盖
    公共无效onCheckedChanged(CompoundButton compoundButton,布尔B){
        chk1.setChecked(假);
        chk2.setChecked(二);
        chk1.setAlpha(0.5F);
        chk2.setAlpha(1F);
    }
});

I currently have a two checkboxes, where when one is clicked, the other automatically unchecks. I would like to keep that however have the unchecked one become a faded white color, yet still be clickable and readable if the user decides to change his/her mind.

This is the current code I have:

 chk1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (CheckBox.isChecked(chk1)) {
            chk2.setChecked(false);
            chk1.setChecked(b);
            chk2.setAlpha(0.5f);
        }
    });

    chk2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (CheckBox.isChecked(chk2)) {
            chk1.setChecked(false);
            chk2.setChecked(b);
            chk1.setAlpha(0.5f);
        }
    });
解决方案

chk2.setAlpha(0.5f) would make it appear faded.

chk1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            chk2.setChecked(false);
            chk1.setChecked(b);
            chk2.setAlpha(0.5f);
            chk1.setAlpha(1f);
        }
    });

chk2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        chk1.setChecked(false);
        chk2.setChecked(b);
        chk1.setAlpha(0.5f);
        chk2.setAlpha(1f);
    }
});

这篇关于如何使一个选项,褪色,但仍然可以点击在Android工作室?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 19:40