0
テキストと画像の両方を持つラジオボタンがあります。私は色のようにその上に色を適用してボタンをクリックすると、画像の色を変更しようとしています。私はandroid:state_checked="true"
を使ってみましたが、イメージの上にカラーを適用することはできません。クリック/押したときのラジオボタン画像の描画色の変更
私はまたしてプログラム的にそれを実行しようとしました:
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
<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" />
を支援@ドレイブル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" />
あなたがnullポインタ例外が、それはそれが正しいファイルであるMr.Popular @現在上映レイアウトファイル –
にあるかどうかを確認してくださいR.id.image_share言っている場合... – Bmbariah