0
此前,我能夠動態創建一個android.widget.Button,其背景色通過Button的背景圖像的透明部分可見。我無法重新創建它。我曾嘗試過:如何通過透明背景圖像創建背景顏色可見的按鈕?
Button button = (Button) findViewById(id.button1);
try {
button.setBackgroundColor(Color.RED);
Bitmap bm = BitmapFactory.decodeStream(getAssets().open("transparent.png"));
button.setBackgroundDrawable(new BitmapDrawable(bm));
button.invalidate();
} catch (IOException e) {
throw new RuntimeException(e);
}
只有圖像是可見的,如果我運行上述。如果我將調用移動到setBackgroundDrawable調用下方的setBackgroundColor,則只能看到紅色,而不是圖像。我該如何做到這一點,以便我可以看到圖像,並通過其透明部分看到背景?
謝謝!這樣做(儘管我仍然想知道如何用普通的舊Button實現它)。 –
如果你做了,也許做一些非常相似的事情,我還沒有嘗試;) – Lumis