Disable/Remove floating label hint text in TextInputLayout XML

前端 未结 11 1332
一向
一向 2021-01-31 06:59

This may seem counter-intuitive but is there a way to disable or remove the floating label hint in TextInputLayout? The reason I want to use TextInputLayout

相关标签:
11条回答
  • 2021-01-31 07:41

    With com.google.android.material you can hide by

    <com.google.android.material.textfield.TextInputLayout
    
                   ....
    
                   app:hintAnimationEnabled="false"
                   app:hintEnabled="false"
                   >
    
                    <com.google.android.material.textfield.TextInputEditText
                        ........
                        android:hint="@string/label_hint"
                        />
    
    </com.google.android.material.textfield.TextInputLayout>
    
    0 讨论(0)
  • 2021-01-31 07:42

    Answer by @Gauthier is correct, but in case you don't want just the floating Hint but you want the Hint before text edit then in addition to disabling Hint for TextInputLayout you should provide hint in EditText widget.

    I guess this answers few of the question raised by some people in above comments.

    0 讨论(0)
  • 2021-01-31 07:44

    update the design library to v23 and add app:hintAnimationEnabled="false" in the TextInputLayout

    0 讨论(0)
  • 2021-01-31 07:45
     <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/etemailLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint=" ">
    
                <EditText
                    android:id="@+id/txtemail"
                    style="@style/login_edittext"
                    android:hint="Enter Your Email Address"
                    android:inputType="textEmailAddress" />
    
            </com.google.android.material.textfield.TextInputLayout>
    
            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/etPasswordLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint=" "
                android:scrollbars="vertical"
                app:counterEnabled="true"
                app:passwordToggleEnabled="true">
    
                <EditText
                    android:id="@+id/txtpassword"
                    style="@style/login_edittext"
                    android:fontFamily="@font/ubuntu"
                    android:hint="Enter Password"
                    android:inputType="textPassword"
                    android:maxLength="8"
                    android:scrollbars="vertical" />
    
            </com.google.android.material.textfield.TextInputLayout>
    

    for apply style to your EditText put below code in Styles.xml ..

    <style name="login_edittext">
            <item name="android:layout_marginTop">15dp</item>
            <item name="android:background">@drawable/edittext_background</item>
            <item name="android:textColorHint">#FFFFFF</item>
            <item name="android:textColor">#FFFFFF</item>
            <item name="android:layout_width">match_parent</item>
            <item name="android:layout_height">wrap_content</item>
        </style>
    

    for backgroud effect create edittext_background.xml in drawable..

    <?xml version="1.0" encoding="utf-8"?>
    <shape android:shape="rectangle"
        xmlns:android="http://schemas.android.com/apk/res/android" >
        <corners android:radius="7dp" />
        <solid android:color="#80ffffff" />
        <padding android:left="10dp" android:right="10dp"
            android:top="10dp" android:bottom="10dp" />
        <stroke android:width="2dp" android:color="#FFFFFF" />
    </shape>
    
    0 讨论(0)
  • 2021-01-31 07:45

    I think this will help you:

    textContainer.setHintAnimationEnabled(false);
    
    0 讨论(0)
提交回复
热议问题