Android EditText view Floating Hint in Material Design

前端 未结 10 2174
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 08:13

Does API 21 provide a method to use the following feature:

http://www.google.com/design/spec/components/text-fields.html#text-fields-floating-labels

I\'m try

10条回答
  •  無奈伤痛
    2020-12-02 09:02

    Import the Support Libraries, In your project's build.gradle file, add the following lines in the project's dependencies:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    
        compile 'com.android.support:design:22.2.0'
        compile 'com.android.support:appcompat-v7:22.2.0'
    }
    

    Use following TextInputLayout in your UI Layout:

    
    
        
    
    
    

    Than, call setHint on TextInputLayout just after setContentView call because, to animate the floating label, you just need to set a hint, using the setHint method.

    final TextInputLayout usernameWrapper = (TextInputLayout) findViewById(R.id.usernameWrapper);
    usernameWrapper.setHint("Username");
    

提交回复
热议问题