How to change the position of a floating label in TextInputLayout in android

I have a rectangular text editor that is inside a TextInputLayout. I want to put some margin between the floating label and the rectangular borders of the edit text, but I cannot do this. I tried different field options, but did not train. here is the screenshot Edit Text

In the image, you can see that the floating label adheres to the upper border of the rectangular editing text. But I want some space between the label and the top border. Thanx in advance.

below is the XML code for EditText

<android.support.design.widget.TextInputLayout android:id="@+id/input_layout_password" android:layout_width="match_parent" android:layout_height="wrap_content" > <EditText android:id="@+id/input_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="email" android:background="@drawable/textbg"/> 

below is the code to output the background

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <stroke android:width="1dp" android:color="@color/colorPrimary"/> /> <padding android:left="15dp" android:right="15dp" android:top="15dp" android:bottom="15dp" /> </shape> 
+8
android android-edittext android-textinputlayout androiddesignsupport
source share
6 answers

I believe that you cannot adjust the position of the TextInputLayout label. and using TranslationY is not a suitable solution to reposition a floating label, because it will translate any representation. if you find any other answer please let me know.

+4
source share

You can specify the height manually for TextInputLayout Like:

 android:layout_height="100dp" 

he works for me.

+1
source share

Use the drop-down background with a list of layers to get debugging on top.

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:top="10dp"> <shape android:shape="rectangle"> <!-- view background color --> <solid android:color="@android:color/transparent"></solid> <stroke android:width="1dp" android:color="@color/colorAccent" /> <!-- If you want to add some padding --> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp"></padding> </shape> </item> </layer-list> 

Using

 <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/label_quantity" android:textColorHint="@color/colorOrange" app:errorEnabled="true" app:errorTextAppearance="@style/ErrorText"> <android.support.design.widget.TextInputEditText android:layout_width="match_parent" android:layout_height="@dimen/login_edit_text_height" android:background="@drawable/drawable_background" android:imeOptions="actionNext" android:inputType="number" android:maxLines="1"/> </android.support.design.widget.TextInputLayout> 
+1
source share

If you have a custom background set to EditText, the android: paddingTop simple attribute does not work to change the b / w spacing of the floating tooltip text and edit the text. Therefore, if you set your own background to your EditText, you can use the android: translationY attribute in EditText.

  <android.support.design.widget.TextInputLayout android:id="@+id/input_layout_password" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/input_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="email" android:translationY="10dp" android:background="@drawable/textbg"/> </android.support.design.widget.TextInputLayout> 

Hope this helps :)

0
source share

To do this, you just need to put the background in the textinputlayout of edttext, as follows

 <android.support.design.widget.TextInputLayout android:id="@+id/input_layout_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/textbg" > <EditText android:id="@+id/input_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="email"/> 

and you just need to specify the top of the top layer in the paintable file.

0
source share

Just add custom EditText background

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <padding android:top="4dp"/> // your padding value </shape> </item> // customize your background items if you need </layer-list> <android.support.design.widget.TextInputLayout ...> <android.support.design.widget.TextInputEditText ... android:background="@style/your_custom_background"/> 

then apply it to your EditText and increase the height of your EditText with your padding value if you use the patch height

0
source share

All Articles