TextInputLayout in Sketchware
To create an EditText with animation features, we can use the EditText in a TextInputLayout which is a Layout interface in android.support.design.widget library. In Sketchware we cannot add it in xml file but we can create it programmatically. Follow the instructions given below for a simple example.
1. In VIEW area of your project add a Linear vertical linear7 and inside this add three EditText fields edit_email, edit_username, and edit_password. For the three EditText fields set hint as Email, Username and Password respectively.
2. Switch On AppCompat and design.
3. In onCreate event,
i. Use codes to remove all Views from linear7.
linear7.removeAllViews();
ii. Define a TextInputLayout textinput1, and add edit_email to it.
com.google.android.material.textfield.TextInputLayout textinput1 = new com.google.android.material.textfield.TextInputLayout(this);
textinput1.addView(edit_email);
iii. Define a TextInputLayout textinput2, and add edit_username to it.
com.google.android.material.textfield.TextInputLayout textinput2 = new com.google.android.material.textfield.TextInputLayout(this);
textinput2.addView(edit_username);
iv. Define a TextInputLayout textinput3, and add edit_password to it.
com.google.android.material.textfield.TextInputLayout textinput3 = new com.google.android.material.textfield.TextInputLayout(this);
textinput3.addView(edit_password);
textinput3.setHelperTextEnabled(true);
textinput3.setHelperText("Password must be at least 7 characters in length");
v. Add all TextInputLayouts to linear7.
linear7.addView(textinput1);
linear7.addView(textinput2);
linear7.addView(textinput3);
4. Save and run the project.
1. In VIEW area of your project add a Linear vertical linear7 and inside this add three EditText fields edit_email, edit_username, and edit_password. For the three EditText fields set hint as Email, Username and Password respectively.
2. Switch On AppCompat and design.
3. In onCreate event,
i. Use codes to remove all Views from linear7.
linear7.removeAllViews();
ii. Define a TextInputLayout textinput1, and add edit_email to it.
com.google.android.material.textfield.TextInputLayout textinput1 = new com.google.android.material.textfield.TextInputLayout(this);
textinput1.addView(edit_email);
com.google.android.material.textfield.TextInputLayout textinput2 = new com.google.android.material.textfield.TextInputLayout(this);
textinput2.addView(edit_username);
iv. Define a TextInputLayout textinput3, and add edit_password to it.
com.google.android.material.textfield.TextInputLayout textinput3 = new com.google.android.material.textfield.TextInputLayout(this);
textinput3.addView(edit_password);
textinput3.setHelperTextEnabled(true);
textinput3.setHelperText("Password must be at least 7 characters in length");
v. Add all TextInputLayouts to linear7.
linear7.addView(textinput1);
linear7.addView(textinput2);
linear7.addView(textinput3);
4. Save and run the project.
Post a Comment