1
我希望我的自定義警報對話框中的圖像視圖爲黑色和白色。 做到這一點(reasearch後),正確的方法是...ImageView黑色和白色不在警報對話框中工作
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
imageview.setColorFilter(filter);
然而,當我的ImageView的是我的自定義警告對話框,這是行不通的。
這裏是我的代碼:
私人無效showDialogForTodayItemClicked(){
// custom dialog
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_daily_food_clicked);
dialog.setTitle("Title...");
ImageView imageview = (ImageView) dialog.findViewById(R.id.image_view_dialog_background_today);
imageview.setBackgroundResource(R.drawable.avocados_small);
ColorMatrix matrix = new ColorMatrix();
matrix.setSaturation(0);
ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
imageview.setColorFilter(filter);
dialog.show();
}
下面是對話的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="300dp"
android:id="@+id/dialog_daily_food_relative_layout"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ffffff"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#81383838"></LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/image_view_dialog_background_today"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textColor="#ffffff"
android:layout_margin="20dp"
android:textStyle="bold"
android:text="MORE INFO"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DONE"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:textStyle="bold"
android:layout_margin="20dp"/>
</RelativeLayout>
感謝這麼多所有。