如何在浓缩咖啡中将MenuItem转换为ActionMenuItem?

时间:2016-11-21 19:31:59

标签: android android-espresso

onView(withId(com.help.R.id.menu_item)).check(matches(CustomMatchers.withActionIconDrawableNumberOflayers(2)));

这里我使用自定义匹配器来检查菜单项上的图层数。

   public static Matcher<View> withActionIconDrawableNumberOflayers(final int numberOflayers) {
    return new BoundedMatcher<View, ActionMenuItemView>(ActionMenuItemView.class) {
        @Override
        public void describeTo(final Description description) {
            description.appendText("has image layers " + numberOflayers);
        }

        @Override
        public boolean matchesSafely(final ActionMenuItemView actionMenuItemView) {
            LayerDrawable icon1 = (LayerDrawable) actionMenuItemView.getItemData().getIcon();
            int i = icon1.getNumberOfLayers();
            return i==numberOfLayers;
        }
    };
}

但是我无法超越这条线

LayerDrawable icon1 = (LayerDrawable) actionMenuItemView.getItemData().getIcon();

如何将MenuItem(com.help.R.id.menu_item)转换为ActionMenuItemView,以便我可以获得菜单项drawable的numberOfLayers?

0 个答案:

没有答案