如果您在ImageView中顯示位圖,則可以使用ImageView.setAlpha(int)
方法。但是,如果通過RemoteViews來接受ImageView,就像更新小部件時一樣,您將無法調用此方法(如果您嘗試通過RemoteViews.setInt(int, String, int)
調用它,您將會得到一個異常,告訴您同樣多)。
private Bitmap adjustOpacity(Bitmap bitmap, int opacity)
{
Bitmap mutableBitmap = bitmap.isMutable()
? bitmap
: bitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
int colour = (opacity & 0xFF) << 24;
canvas.drawColor(colour, PorterDuff.Mode.DST_IN);
return mutableBitmap;
}
更多info。最常見的就像你的問題。 How to Set Opacity (Alpha) for View in Android
Documentation位圖來自developer.android.com。
我將android:alpha =「。5」添加到位圖定義中,但沒有運氣。其他人能夠解決這個問題嗎? – lostintranslation