雖然在 layout.xml 中定義 enabled="false",AndroidStudio 並不會報錯,但在 app 執行時並沒有產生作用;官網的 ImageButton 參考頁也沒有找到 enabled 的屬性,似乎只能在 app 執行時設定。
...
...
<ImageButton
android:id="@+id/Button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/圖檔" 本次採用 向量圖檔(vector asset), 所以可在程式中改變圖檔的顏色
android:background="@android:color/transparent" 指定按鈕的背景為透明
android:enabled="true" /> 這個屬性在 app 執行時並沒有產生作用
...
...
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var button1 = findViewById<ImageButton>(R.id.Button1)
button1.isEnabled = false
// 即使被 disabled 了, button1 所引用的圖檔顏色並沒有任何變化
// 所以也要自行改變圖檔的顏色
button1.setColorFilter(getColor(R.color.black))
}
沒有留言:
張貼留言