2017-01-05 3 views
0

Das ist, was ich habe jetzt, aber es ist falsch, jedes MalIch möchte wissen, wie ich die Farbe meiner Imageview auf Android Studio überprüfen

if(ivBall.equals(Color.RED)) 
     { 
      Toast.makeText(getApplicationContext(), "good", Toast.LENGTH_SHORT).show(); 
     } 
     else 
     { 
      Toast.makeText(getApplicationContext(), "wrong", Toast.LENGTH_SHORT).show(); 
     } 
+0

Was ist der Fehler? – RamPrakash

+2

Was ist ivBall ..? eine Farbe? ein Objekt? Mehr Info! – LostKatana

+0

das ist meine Bildansicht –

Antwort

0

Set Farbe Image:

ivBall.setBackgroundColor(Color.RED); 

Try Verwenden Sie dazu:

ColorDrawable drawable = (ColorDrawable) ivBall.getBackground(); 
    if(drawable.getColor() == Color.RED) 
    { 
     Toast.makeText(getApplicationContext(), "good", Toast.LENGTH_SHORT).show(); 
    } 
    else 
    { 
     Toast.makeText(getApplicationContext(), "wrong", Toast.LENGTH_SHORT).show(); 
    } 
+0

es sagt: "kann Methode nicht auflösen 'gleich (int)'" –

+0

Versuchen Sie 'Drawable.getColor() == Color.RED' – W4R10CK

+0

Wenn ich auf die Bildansicht klicke, wird die App schließen –

Verwandte Themen