簡體   English   中英

Android:檢查背景資源可繪制

[英]Android: Checking Background Resource 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
        }

如果不是,單擊時將執行其他操作

        else {
               //Another Action
        }
   }

您可以對兩個按鈕使用View類的getBackground()方法,並進行如下比較:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM