Setting cursor to the right on an EditText with HINT Gravity to center

萝らか妹 提交于 2019-12-01 22:34:08

问题


Is this possible? Any EditText attribute to do so?

Thanks.


回答1:


You can use

android:ellipsize="end"
android:gravity="center"

in your xml when you declare the EditText

The first line is to move cursor to the right and the second one to move the hint to the center. An example:

<EditText
    android:id="@+id/txt1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:gravity="center"
    android:hint="@string/your_hint_id"
/>



回答2:


This should be the better solution and it worked for me.

<EditText 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:text="1234" 
android:layout_weight="1" 
android:id="@+id/editText1" 
android:gravity="center_horizontal"></EditText>


来源:https://stackoverflow.com/questions/22694800/setting-cursor-to-the-right-on-an-edittext-with-hint-gravity-to-center

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