我有以下代码:
我有以下代码:
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;
});
虽然总体上看起来它是可以工作的,但我突然收到了一个Crashlytics报告,报告内容如下:
尝试在空对象引用上调用虚拟方法'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" />