我有一個ImageButton的:更改形狀顏色
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
app:srcCompat="@drawable/round_color"
android:layout_below="@+id/lamps_list_room"
android:layout_alignStart="@+id/lamps_list_room"
android:layout_marginStart="69dp"
android:layout_marginTop="62dp"
android:id="@+id/color_picker_button"
android:background="@color/colorPrimaryDark"/>
和形狀:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:radius="100dp" />
<stroke
android:color="#FFFFFF"
android:width="2px">
</stroke>
</shape>
什麼是改變形狀的實體顏色的最佳方法?
ImageButton imageButton = (ImageButton) ((Activity) mContext).findViewById(R.id.color_picker_button);
Drawable drawable = imageButton.getBackground();
drawable.setColorFilter(0xff999999, PorterDuff.Mode.MULTIPLY);
形狀仍然是白色的...
編輯:
甚至當我嘗試
Drawable drawable = mContext.getDrawable(R.drawable.round_color);
ColorFilter filter = new LightingColorFilter(Color.BLACK, Color.BLACK);
if (drawable != null) {
drawable.setColorFilter(filter);
}
它仍然無法正常工作!
此[鏈接](http://stackoverflow.com/a/17825210/1907954)可以幫助你。它已經在SO中得到了回答。 – Bugdr0id
可能重複的[以編程方式設置android形狀顏色](http://stackoverflow.com/questions/17823451/set-android-shape-color-programmatically) –