[英]Drawable resource file - Changing Image
詳細描述:
因此,我希望靜止圖像根據情況而有所不同。 一旦用戶獲得貨幣(以我為例),我希望它檢查是否有足夠的購買能力。 如果他有足夠的功能,我希望按鈕可以更改顏色,以便直觀地告訴用戶他有足夠的能力購買此升級。 每當他的貨幣價值改變時,我都會調用此函數。 盡管生活並不完美,但是我無法在xml中組合Java代碼,而且也不知道如何調用它。
摘要:
我的問題是如何通過我的mainActivity更改@ drawable / button
我想發生的事的例子:
aFunction(){
if(whatever){
<item android:drawable="@drawable/buttonclick" android:state_pressed="true"></item>
<item android:drawable="@drawable/button"></item>
}
else
<item android:drawable="@drawable/buttongray"></item>
}
在您的xml中:
<item android:drawable="@drawable/button"></item>
<item android:drawable="@drawable/buttonclick" android:state_pressed="true"></item>
<item android:drawable="@drawable/buttongray" android:state_enabled="false"></item>
並在您的JAVA代碼中:
if(whatever){
button.setEnabled(true);
} else {
button.setEnabled(false);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.