0
我有一個既有文字又有圖像的單選按鈕。我試圖改變圖像的顏色,當按鈕被點擊時,通過在它上面應用一種顏色,如色調。我嘗試使用android:state_checked="true"
,但它不允許我在圖像上應用顏色。單擊/按下時更改可繪製Radiobutton圖像的顏色
我也試圖做到這一點的編程:
RadioButton radioButtonShare= (RadioButton) findViewById(R.id.image_share);
radioButtonShare.getButtonDrawable().setColorFilter(getResources().getColor(R.color.colorPrimaryDark), PorterDuff.Mode.SRC_ATOP);
但它與nullpointexception崩潰...
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.drawable.Drawable.setColorFilter(int, android.graphics.PorterDuff$Mode)' on a null object reference
請協助
單選
<RadioButton
android:id="@+id/image_share"
style="@style/style_radiobutton"
android:layout_height="match_parent"
android:drawableTop="@drawable/selector_image_share"
android:text="@string/edit_share" />
@ drawabl E/selector_image_share
<item android:drawable="@drawable/viewer_ic_share" android:state_checked="true" />
<item android:drawable="@drawable/viewer_ic_share" android:state_pressed="true" />
<item android:drawable="@drawable/viewer_ic_share" />
如果說空指針異常,然後檢查R.id.image_share無論是在當前的顯示佈局文件 –
@ Mr.Popular它是正確的文件... – Bmbariah