TextInputLayout not showing EditText hint before user focus on it

后端 未结 16 843
时光说笑
时光说笑 2020-11-27 13:50

I am using recently released Android Design Support Library to show floating label with EditTexts. But i am facing the problem that the Hint on the EditText is not showing w

相关标签:
16条回答
  • 2020-11-27 14:12

    If you are setting your EditText hint programmatically it wouldn't work! You need to set the hint on the TextInputLayout it self.

    TextInputLayout textInputLayout = (TextInputLayout) findViewById(R.id.usernameTextInputLayout);
    textInputLayout.setHint(getString(R.string.username_hint));
    

    Here is the XML in case you are wondering:

            <android.support.design.widget.TextInputLayout
                android:id="@+id/usernameTextInputLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
    
                <android.support.v7.widget.AppCompatEditText
                    android:id="@+id/usernameEt"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/default_height"
                    android:layout_marginEnd="@dimen/default_margin"
                    android:layout_marginStart="@dimen/default_margin"
                    android:maxLength="@integer/username"
                    tools:hint="Username" />
    
            </android.support.design.widget.TextInputLayout>
    
    0 讨论(0)
  • 2020-11-27 14:13

    This issue is fixed in version 22.2.1

    0 讨论(0)
  • 2020-11-27 14:13

    This issue is resolved in v23.0.1 of support design library. I also updated my appcompat-v7 to 23.0.1, compileSdkVersion to 23 & buildToolsVersion to 23.0.1 in build.gradle.

    android {    
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    }
    
    dependencies {
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    }
    
    0 讨论(0)
  • 2020-11-27 14:14

    Problem is the hint color. It becomes white when typing something. Please change the hint color or change the background color. You will see the hint while typing.

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题