【发布时间】:2020-02-09 18:59:56
【问题描述】:
我有以下代码:
etEmail.setOnTouchListener((view, motionEvent) -> {
final int DRAWABLE_RIGHT = 2;
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
if(motionEvent.getRawX() >= (etEmail.getRight() - etEmail.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
Utils.getInstance().showPopup("...",MainActivity.this,null);
return true;
}
}
return false;
});
虽然通常它似乎有效,但我突然收到一份崩溃分析报告:
尝试调用虚拟方法'android.graphics.Rect android.graphics.drawable.Drawable.getBounds()' 在一个空对象上 参考
适用于品牌:小米,型号:Redmi Note 6 Pro,Android:9。
这里有没有人知道什么会导致drawable“消失”或被视为null?
XML 布局:
<EditText
android:id="@+id/etEmail"
tools:ignore="Autofill"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/ic_info"
android:paddingEnd="12dp"
android:paddingStart="10dp"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
【问题讨论】:
-
你知道drawable是否显示了吗?
-
我不知道,它来自用户
标签: android compound-drawables