【问题标题】:Android: Checking Background Resource DrawableAndroid:检查背景资源可绘制
【发布时间】:2013-05-04 14:20:42
【问题描述】:

请帮助我们如何进行背景资源检查?

例子:

  Button button1;

  protected void onCreate(Bundle savedInstanceState) {
  ..........................................
  button1 = (Button) findViewById(R.id.example1);
  }

  public void onclick1 (View v){
         button1.setBackgroundResource(R.drawable.example2);
  }

  public void onclick2 (View v){

我的问题在这里,检查button1 button drawable = example2

        if (..........................){
               //Action
        }

如果没有,点击时会执行另一个动作

        else {
               //Another Action
        }
   }

【问题讨论】:

    标签: android background resources drawable


    【解决方案1】:

    您可以对两个按钮使用 View 类的 getBackground() 方法,并像这样进行比较:

    if (button1.getBackground().getConstantState().equals(button2.getBackground().getConstantState())) {
        }
    else {
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2022-12-22
      • 1970-01-01
      • 2015-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多