2017-07-21 9 views

答えて

0

問題が解決しました。ソリューションであり、ここので

私の友人は、リストの要素の色マッチングを実装誰かが将来的にこれを必要としますmeybeする方法を私に示しています

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: "); 
    } 
} 

そして今、あなたには、いくつかのリスト要素の色を確認したい場合使用:

onView(withRecyclerView(R.id.ItemFromListRecyclerView).atPosition(2)) 
       .check(matches(new ColorMatcher(R.color.element_defined_color))); 
関連する問題