How to Change the Floating Label position of TextInputLayout in android

how to change the floating label color of textinputlayout
customize textinputlayout android
com.google.android.material.textfield.textinputlayout not working
android textinputlayout clear button
com.google.android.material.textfield.textinputlayout hint color
android support/design widget textinputlayout not found
com.google.android.material.textfield.textinputlayout example
android.support.design.widget.textinputlayout androidx

I have a rectangular shaped Edit Text which is inside the TextInputLayout. I want to put some margin between floating label and rectangular boundaries of edit text but i am not able to do that. I tried different margins parameters but it didn't workout.

In the image you can see that floating label is stick with the upper boundary of the rectangular edit text. But i want some space between label and upper boundary. 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 for background drawable

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

I believe that you can not customize the label position TextInputLayout. and using TranslationY is not the suitable solution for changing the floating label postion because it will translate any view. if you find any other answer please let me know.

TextInputLayout (Floating Label EditText), To display floating label in EditText, TextInputLayout needs to wrapped the EditText. start inputting the text it starts animating by moving to floating label position. setHint("Enter UserName"); // set the hint to be displayed in the floating label. Below we set the hint to be displayed in the floating label. TextInputLayout simpleTextInputLayout = (TextInputLayout) findViewById(R.id.simpleTextInputLayout); // get the reference of TextInputLayout simpleTextInputLayout.setHint("Enter UserName"); // set the hint to be displayed in the floating label.

You can give the height manually to TextInputLayout Like :

android:layout_height="100dp"

it work for me.

TextInputLayout / Floating Labels In EditText With , Android TextInputLayout Example, Android Text Input Layout, android floating hints, TextInputLayout has much more to offer than just displaying floating hint labels. and while writing this tutorial, there's no way to change the position, yet. To display a Floating Text or Label when user clicks on the EditText. Prerequisite : To use TextInputLayout in your android application, you need to include the ‘com.android.support.design’ package in your build.gradle (app) dependencies. There are different available versions of the package.

Use drawable background with layer list to get some padding from 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>

Usage

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

Android TextInputLayout Example, Set the hint to be displayed in the floating label, if enabled. void, setHintAnimationEnabled(boolean enabled). Set whether any hint state changes, � With reference to the new TextInputLayout released by Google, how do I change the floating label text color?. Setting colorControlNormal, colorControlActivated, colorControlHighLight in styles does not help.

If you have custom background set on EditText the android:paddingTop attribute simple doesn't work to alter the spacing b/w the floating hint text and edit text. So if you have set custom background to your EditText, you can use android:translationY attribute in the 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 :)

TextInputLayout, Android Design Support Library: TextInputLayout - Floating Label it is possible to control this hint so that it disappears as soon as the user starts writing the text and "moves" to the label position: We set the error message. Android design support library introduced TextInputLayout – floating label and some other important new widget that helps developers to create consistent UI following material design guidelines. One of the new component shipped by Android design support library is TextInputLayout that is used to animate EditText labels .

For that you just have to put background in the textinputlayout from edttext as follow

<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 have to specify padding top in drawable file.

Android Design Support Library: TextInputLayout, Explained how to add support library to use TextInputLayout & TextInputEditText, how to enable password visibility toggle, how to show error� One of the new component shipped by Android design support library is TextInputLayout that is used to animate EditText labels. To do the job, TextInputLayout uses an EditText attribute, called hint

Android TextInputLayout - Android floating label, Android's text field component APIs support both label text and helper text for informing the user as to what gets set, the TextInputLayout has to make sure that the edit text's Collapsed (floating) color, app:hintTextColor, setHintTextColor com.google.android.material.textfield.TextInputLayout Layout which wraps a TextInputEditText , EditText , or descendant to show a floating label when the hint is hidden while the user inputs text.

Text Fields - Material Design, how to change the floating label color of textinputlayout com.google.android. material.textfield.textinputlayout not working. This may Android After that when a user start inputting the text it starts animating by moving to floating label position. Change EditText hint color when using TextInputLayout (14) I am using the new TextInputLayout from the design library. I am able to get it to show and to change the color of the floating label. Unfortunately the actual EditText hint is now always white.

Disable/Remove floating label hint text in TextInputLayout XML, I have a PR I'm working on now to vertically center the label text. It should the label. Since android:paddingTop is set to 20dp in Widget. Created standard styles for TextInputLayout kickstarter/android-oss#458 Can align hint text start, center and right, but does not seem to be able to do so vertically. Android TextInputLayout is nothing but a layout which is used specifically to wrap an EditText and show floating labels. Android TextInputLayout can be used to wrap one EditText at a time. When an Android TextInputLayout is used around an EditText is automatically takes the hint text defined in the EditText and shows it as a floating label.

Comments
  • Use this link to solve your problem. androidhive.info/2015/09/… Hope this will help you. All the best.
  • You can refer to this answer: stackoverflow.com/questions/32609710/…
  • You can refer to this link: stackoverflow.com/questions/32609710/…
  • thanx for replying and agree with your comment
  • It works exactly as expected. But also you need to set gravity=bottom for TextInputLayout to additional height appears on the top.
  • not working . moreover your code is for solid rectangle shape and my question is for hollow rectangle
  • Well, you can go for hollow by editing the drawable. I have updated the answer. It must works.
  • <item android:top="10dp"> made some tricks but now edittext cursor and hint looks bend more towards the top boundary of the rectangle when not focused . And i think it will be visible according to screen resolution/size of the phone
  • android:translationY="10dp" it will translate edit text or in fact any View.
  • yes your solution works as per question but it also change the position of original hint(when it wasn't focused).