gpt4 book ai didi

android - 使用 Espresso 检查 EditText 的字体大小、高度和宽度

转载 作者:行者123 更新时间:2023-11-29 01:05:43 24 4
gpt4 key购买 nike

如何使用 Espresso 检查 EditText 的字体大小、高度和宽度?

目前要分割我使用的文本:

onView(withId(R.id.editText1)).perform(clearText(), typeText("Amr"));

阅读文本:

onView(withId(R.id.editText1)).check(matches(withText("Amr")));

最佳答案

您必须创建自己的自定义匹配器,因为默认情况下 Espresso 不支持任何这些匹配器。

幸运的是,这可以很容易地完成。看看这个字体大小的例子:

public class FontSizeMatcher extends TypeSafeMatcher<View> {

private final float expectedSize;

public FontSizeMatcher(float expectedSize) {
super(View.class);
this.expectedSize = expectedSize;
}

@Override
protected boolean matchesSafely(View target) {
if (!(target instanceof TextView)){
return false;
}
TextView targetEditText = (TextView) target;
return targetEditText.getTextSize() == expectedSize;
}


@Override
public void describeTo(Description description) {
description.appendText("with fontSize: ");
description.appendValue(expectedSize);
}

然后像这样创建一个入口点:

public static Matcher<View> withFontSize(final float fontSize) {
return new FontSizeMatcher(fontSize);
}

然后像这样使用它:

onView(withId(R.id.editText1)).check(matches(withFontSize(36)));

对于宽度和高度,可以用类似的方式完成。

关于android - 使用 Espresso 检查 EditText 的字体大小、高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47398659/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com