更改EditText错误提示的图标位置

9
对于将填充RTL文本的EditText,是否有一种方法可以更改错误可绘制对象(当然还有弹出窗口)的重力?以下是常规错误可绘制对象的示例。

error drawable always right

因为输入的文本是RTL,所以我希望弹出窗口显示在EditText的左侧。

我尝试应用自定义Drawable,但Drawable似乎没有任何setGravity方法。

提前感谢。

2个回答

1

正常情况下不可能实现,但是你可以扩展Android TextView类并更改Android用于填充弹出窗口的布局。我自己没有尝试过,但这可能有效。

我快速查看了TextView的源代码,找到了这一行

final TextView err = (TextView) inflater.inflate(com.android.internal.R.layout.textview_hint,
                   null);

这句话的意思是:引用了this布局。
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/popup_inline_error"
    android:textAppearance="?android:attr/textAppearanceSmallInverse"
/>

在这里添加重力可能会有奇效。对于可绘制对象,可以采用类似的方法。

-2

已经过去一年了,但如果对其他人有帮助的话,你可以使用以下方法:

myEdit.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_error, 0, 0, 0);

但它会一直保留,直到您将其删除

myEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);

问题不是关于编程设置可绘制,而是关于更改可绘制的重力。 - Ganesh Mohan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接