簡體   English   中英

從drawable獲取資源ID

[英]Get the resource id from a drawable

在xml中:

<ImageButton
    android:id="@+id/b_checkEv" 
    android:src="@drawable/img_huella" 
    ... />

活動中:

     ImageButton ib = (ImageButton) findViewById(R.id.b_checkEv);
     Drawable dr = ib.getDrawble();

我使用ib.setDrawable()在代碼中動態更改ImageButton的圖像。 誰知道我該如何從Drawable中獲取資源ID,以便知道每時每刻在ImageButton中設置了哪個圖像?

謝謝!

控制Android按鈕的最佳方法是標簽。

您可以在此處執行“ ib.setTag(“ image1.png”)”並管理圖像數據。

然后,您可以執行“ String imageName = ib.getTag()”並獲取圖像名稱。

問候

暫無
暫無

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

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