Amo*_*mos 3 android compound-drawables
我有以下代码:
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;
});
Run Code Online (Sandbox Code Playgroud)
虽然通常它似乎有效,但我突然收到一份崩溃报告说:
尝试在空对象引用上调用虚拟方法“android.graphics.Rect android.graphics.drawable.Drawable.getBounds()”
适用品牌:小米,型号:Redmi Note 6 Pro,Android:9。
这里有人知道什么会导致可绘制对象“消失”或被视为空吗?
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" />
Run Code Online (Sandbox Code Playgroud)
在您的 xml 中,它显示为drawableEnd,而在您的代码中,您假设它是右侧的可绘制对象。我有一种感觉,崩溃发生在使用 RTL 语言的设备上(这意味着,可绘制对象将位于左侧)。
| 归档时间: |
|
| 查看次数: |
7516 次 |
| 最近记录: |