Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Floating Labels for EditText in Material Design

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 333
    Comment on it

    Hi, We can show floating label for EditText by using android design support library.

    When we input text on EditText, it shows animation by floating labels.

    TextInputlayout is newly introduced to show floating label on EditText in design support library.
    EditText needs to be covered by TextInputlayout to show animation.

    Here I am writing code to show floating labels in EditText.


    First add dependency in gradle file build.gradle

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

    This is the xml file.

    <android.support.design.widget.textinputlayout android:id="@+id/float_username" android:layout_width="match_parent" android:layout_height="wrap_content"> /android.support.design.widget.textinputlayout>
      <EditText 
            android:id="@+id/username_edittext" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:hint="@string/email" /> 
    
    </android.support.design.widget.TextInputLayout> 
    

    Then use simply as we do with EditText.

        private TextInputLayout inputLayoutUserName; 
     private EditText usernameEditText; 
        @Override 
        protected void onCreate(Bundle savedInstanceState) { 
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.activity_main); 
    
    
            inputLayoutUserName = (TextInputLayout) findViewById(R.id. float_username); 
            usernameEditText = (EditText) findViewById(R.id. username_edittext); 
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: