How to center tooltip text in EditText in Android?

I need to center the help text in EditText on Android. How to do it?

+45
android
Jul 03 2018-12-12T00:
source share
9 answers

To center the hint text for working with EditText, you need to make sure that android: ellipsize = "start". I do not know why this makes it work, but it is.

Example extracted from personal code:

 <EditText android:id="@+id/player2Name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:ellipsize="start" android:gravity="center_horizontal" android:hint="@string/player2_name" android:inputType="textCapWords|textPersonName" android:singleLine="true" /> 
+62
Jul 03 2018-12-12T00:
source share
— -

Actually android:gravity="center_horizontal" acts "center". you can use

Android: Gravity = "Start"

to put the tooltip text at the beginning of the EditText view, etc.

+27
May 28 '14 at 16:42
source share

Use this xml attribute:

Android: Gravity = "Center"

+24
Jul 03 2018-12-12T00:
source share

Use attribute

 android:gravity="center" 
+8
Aug 04 '14 at 9:27
source share

I used this code under any circumstances, and it works fine without using android: ellipsize = "start" to make a hint in the center.

  <EditText android:id="@+id/player2Name" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:hint="robi" android:inputType="text" /> 
+6
Nov 13 '14 at 10:35
source share

Unfortunately, none of the answers helped me reconcile the hint written in LTR, while the layout orientation was RTL. I needed such a layout in the form of a translation application to make overlay icons not interfering with RTL text. But this trick didn’t work with tooltips, as long as there was no text (icons appeared above the tooltip), and I came to the following java solution to the layout problem:

 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { . . . if (isRightToLeft()){ EditText guess = (EditText) rootView.findViewById(android.R.id.text1); CharSequence hint = "\u200F" + guess.getHint(); guess.setHint(hint); } . . . } 

The trick was a label from right to left to add a line from left to right. And it seems to work, but does anyone know a more elegant solution?

+3
May 09 '15 at 12:20
source share

I think the answer should be:

 android:textAlignment="center" 
+2
Sep 04 '16 at 13:50
source share

textAlignment worked for me.

 textAlignment="center" 
+2
Feb 27 '17 at 11:58
source share

This worked for me:

 <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/nombreslayoutinput"> <EditText android:id="@+id/nombreslayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/nombres" android:layout_centerInParent="true" android:gravity="center|center_vertical" android:ellipsize="start" android:inputType="textCapWords|textPersonName" /> </android.support.design.widget.TextInputLayout> 
0
Jul 21 '17 at 20:52
source share



All Articles