Android:检查背景资源可绘制对象

标签 android background resources drawable

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

例子:

  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
        }

如果没有,点击时会做另一个 Action

        else {
               //Another Action
        }
   }

最佳答案

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

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

关于Android:检查背景资源可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16375289/

相关文章:

java - MissingResourceException : Can't find bundle for base name resources. controls.controls_res,语言环境

linux - GNU makefile 中的 Qt 资源

android - 如何在android中将布局分成四个相等的部分?

android - OpenSSLSocketImpl.getSession 崩溃

android - Listview Textview 删除线

java - 使用 Android 应用程序将文件上传到我的 Google API 项目

android - 自定义键盘键文本阴影删除

web - SVG 透明背景网页

java - 如何在 JLayeredPane 上设置背景颜色?

android - Android 的 Scala 编程