我得到這個錯誤在我的代碼錯誤扔在改變alpha屬性
((View) findViewById(R.id.view)).setAlpha(100);
//with float value also doesn't works
alpha屬性設置爲視圖
java.lang.NoSuchMethodError: android.view.View.setAlpha
可能是什麼問題?我沒有任何編譯只是在運行時錯誤
我得到這個錯誤在我的代碼錯誤扔在改變alpha屬性
((View) findViewById(R.id.view)).setAlpha(100);
//with float value also doesn't works
alpha屬性設置爲視圖
java.lang.NoSuchMethodError: android.view.View.setAlpha
可能是什麼問題?我沒有任何編譯只是在運行時錯誤
隨着documentation狀態,setAlpha
需要API 11.你可能有你的minSDK設置爲低於11的東西,正在安裝/設備,低於11即上運行此工具它沒有這個方法,所以Java找不到它。
tnx,我總是忘記看api級別:( – Lukap
我用代碼來設置圖像本身的Alpha,而不是視圖。這是可以從API級別1 ..
public void toggleButton(int i) {
if (indImageBtnEnabled[i]) {
int di = getDrawableId(findViewById(myImagebtns[i]));
Drawable d = this.getResources().getDrawable(di);
d.setAlpha(25);
((ImageView) findViewById(myImagebtns[i])).setImageDrawable(d);
indImageBtnEnabled[i] = false;
} else {
// findViewById(myImagebtns[i]).setAlpha(1f) << NEEDS API11;
int di = getDrawableId(findViewById(myImagebtns[i]));
Drawable d = this.getResources().getDrawable(di);
d.setAlpha(255);
((ImageView) findViewById(myImagebtns[i])).setImageDrawable(d);
indImageBtnEnabled[i] = true;
}
}
setAlpha()此方法在API級別被廢棄16.
使用setImageAlpha(INT)代替
可能你的android:targetSdkVersion高於15,所以你可以驗證何時使用setAlpha或
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
((View) findViewById(R.id.view)).setImageAlpha(100);
} else {
((View) findViewById(R.id.view)).setAlpha(100);
}
的Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
值爲15
setAlpha()是不存在前版本3.0..which是烏爾版本?? –