簡體   English   中英

Android獲取ImageButton的背景資源

[英]Android Get the Background Ressource of an ImageButton

我需要獲取一些ImageButton的后台資源,以便稍后重新使用它,設置后台我使用setBackgroundResource。 我沒有找到任何方法來獲取backgroundressource。

private void AddImage(int img){
    ImageButton imgact1 = (ImageButton)findViewById(R.id.imgact1);
    ImageButton imgact2 = (ImageButton)findViewById(R.id.imgact2);
    ImageButton imgact3 = (ImageButton)findViewById(R.id.imgact3);
    imgact3.setBackgroundResource(img);
}

謝謝你的幫助 。

對於任何View ,你應該使用getBackground() ,它返回一個Drawable

暫無
暫無

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

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