2017-07-21 3 views

Répondre

0

Problème résolu!

Mon ami me montrer comment mettre en œuvre matcher de couleur pour l'élément de la liste, meybe quelqu'un aura besoin de ce à l'avenir alors voici la solution:

public class ColorMatcher implements Matcher<View> { 

    private final int matchColor; 

    public ColorMatcher(int matchColor) { 
     this.matchColor = matchColor; 
    } 

    @Override 
    public boolean matches(Object item) { 
     Context context = ((View)item).getContext(); 
     int c2 = context.getColor(this.matchColor); 
     int c1 = ((ColorDrawable)((View)item).getBackground()).getColor(); 
     return c1 == c2; 
    } 

    @Override 
    public void describeTo(Description description) { 
     description.appendText("with text color: "); 
    } 
} 

Et maintenant, si vous voulez vérifier la couleur de certains éléments de la liste utiliser:

onView(withRecyclerView(R.id.ItemFromListRecyclerView).atPosition(2)) 
       .check(matches(new ColorMatcher(R.color.element_defined_color)));