Change EditText setError drawable gravity

此生再无相见时 提交于 2019-12-08 17:43:25

问题


For EditText that going be filled with RTL text, is there a way to change the gravity of the error drawable (and popup of course) ?

here is an example of regular error drawable

so since the text entered is RTL i would like the pop up to show up at the LEFT side of the EditText

i tried to apply custom drawable , but Drawable doesnt seem to have any setGravity method.

thanks in advance.


回答1:


It's not possible by normal means, however you can extend the Android TextView class and change the layout that Android uses to inflate the popup. I haven't tried this myself but it could work.

I did a quick look in the source of TextView and found this line

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

Which references to this layout.

<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"
/>

Adding gravity here could do the trick. A similar approach for the drawable could apply.




回答2:


It's over a year, but if it helps anyone else, you can use:

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

but it will stay until you remove it

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


来源:https://stackoverflow.com/questions/15173785/change-edittext-seterror-drawable-gravity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!