【问题标题】:How to change backround color of layout dynamically using check box in android?如何使用android中的复选框动态更改布局的背景颜色?
【发布时间】:2011-08-31 22:25:49
【问题描述】:

当检查布局内的复选框时,选中后的布局应该是白色的,如果复选框是未选中的布局应该是black.is在Android中可以在Android ??

【问题讨论】:

    标签: android checkbox customization


    【解决方案1】:

    一些可以帮助您入门的示例代码:

    if(checkbox.isChecked())
      findViewById(R.id.background).setBackgroundColor(Color.WHITE);
    else
      findViewById(R.id.background).setBackgroundColor(Color.BLACK);
    

    【讨论】:

      【解决方案2】:

      你试试 `

      checkBox.setOnClickListener(new OnClickListner(){
      

      layout = finViewById(R.Layout.LinearLayout); layout.setBackgroundColor(//颜色)

      })

      语法不正确..`

      【讨论】:

        【解决方案3】:
        checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if(isChecked){
                            youtLayout.setBackgroundColor(Color.WHITE);
        
                        }else{
                            youtLayout.setBackgroundColor(Color.BLACK);
        
                        }               
                    }
                });
        

        【讨论】:

          猜你喜欢
          • 2012-10-05
          • 2020-05-19
          • 1970-01-01
          • 2016-01-22
          • 1970-01-01
          • 2011-08-17
          • 2014-09-28
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多