如何比较两个drawables,我这样做但没有取得任何成功
public void MyClick(View view)
{
Drawable fDraw = view.getBackground();
Drawable sDraw = getResources().getDrawable(R.drawable.twt_hover);
if(fDraw.equals(sDraw))
{
//Not coming
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个ImageView并设置了一个drawable.现在我需要ImageView动态获取可点击事件的ID .我怎么才能得到它?
imgtopcolor = (ImageView) findViewById(R.id.topcolor);
imgtopcolor.setImageResource(R.drawable.dr); // How do I get this back?
Run Code Online (Sandbox Code Playgroud)
现在触摸事件imgtopcolor我想要绘制id因为我每次都设置不同的drawable并且想要将drawable与其他
是否可以使用浓缩咖啡检查背景颜色是否与给定颜色匹配?
我制作了一个自定义匹配器,类似于@Irfan建议的,谢谢!
public static Matcher<Object> backgroundShouldHaveColor(int expectedColor) {
return buttondShouldHaveBackgroundColor(equalTo(expectedColor));
}
private static Matcher<Object> buttonShouldHaveBackgroundColor(final Matcher<Integer> expectedObject) {
final int[] color = new int[1];
return new BoundedMatcher<Object, Button>( Button.class) {
@Override
public boolean matchesSafely(final Button actualObject) {
color[0] =((ColorDrawable) actualObject.getBackground()).getColor();
if( expectedObject.matches(color[0])) {
return true;
} else {
return false;
}
}
@Override
public void describeTo(final Description description) {
// Should be improved!
description.appendText("Color did not match "+color[0]);
}
};
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Espresso 断言是否在 Android 中的图像视图上显示了正确的图像。图像以 SVG 格式提供,并使用 Android Studio 转换器直接转换为可绘制的矢量。我的自定义匹配器对某些图像进行了成功的测试,但对其他图像却没有。如果我交换 SVG XML 文件,那么结果会与现在失败的结果相反,这让我怀疑这可能与检查 SVG 本身有关,这可能是由于某些路径的字符数量,就像我delete some lines那样包含比其他字符更多的字符,但不确定如何正确修复它。
这是有效的SVG
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="80dp"
android:height="80dp"
android:viewportWidth="80"
android:viewportHeight="80">
<path
android:pathData="M37.2,37.1m-34.85,0a34.85,34.85 0,1 1,69.7 0a34.85,34.85 0,1 1,-69.7 0"
android:fillColor="#fff"/>
<path
android:pathData="M49.22,19.23h2.67A4.79,4.79 0,0 1,56.67 24V53.39a4.79,4.79 0,0 1,-4.78 4.77H22.51a4.79,4.79 0,0 1,-4.78 -4.77V24a4.79,4.79 0,0 1,4.78 -4.77h3.2"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M45.37,24.93a8.9,8.9 0,1 1,-8.9 -8.9A8.9,8.9 0,0 1,45.37 24.93Z"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M35.88,25.46L40.08,21.72"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
</vector>
Run Code Online (Sandbox Code Playgroud)
但这是不起作用的SVG
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="80dp" …Run Code Online (Sandbox Code Playgroud)