2017-07-17 6 views
1

Ich möchte die Bildansicht in meinem benutzerdefinierten Warndialog schwarz und weiß sein. Der richtige Weg, dies zu tun (nach reasearch) ist ...ImageView schwarz und weiß funktioniert nicht im Alarmdialog

ColorMatrix matrix = new ColorMatrix(); 
     matrix.setSaturation(0); 

     ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix); 
     imageview.setColorFilter(filter); 

Dies ist jedoch nicht funktioniert, wenn mein Imageview ein Warnhinweis meine Gewohnheit ist.

Hier ist mein Code:

private void 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(); 

}

Hier ist die xml für den Dialog:

<?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> 

Vielen Dank an alle.

Antwort

1

Die Antwort ist, wenn ich diese verwendet es funktionierte:

imageview.setImageResource(currentItem.getImage()); 

(statt setBackgroundImage).

Verwandte Themen