Google's new standard for unifying the vision and experience of the Android system is Android Design. To make the old system compatible with the new standards, Google offers the Android Design Support Library package, in which Android offers many new controls. And Textinputlayout is from the Android Design Support Library package.
Textinputlayout is a new layout, from the inheritance tree, it inherits from LinearLayout, but it does not support android:orientation properties, as Textinputlayout and ScrollView, Only controls in which the only control can be migrated. Also from Textinputlayout the name of this layout can be guessed, which is a layout specifically designed for text input actions. So textinputlayout is generally a control such as EditText or Autocompletetextview, Textinputlayout provides a better display and experience for these controls.
Here is an example of a edittext that demonstrates the use and effects of textinputlayout. The layout file is as follows:
<android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:counterEnabled="true" app:counterMaxLength="5" app:hintAnimationEnabled="true" app:counterOverflowTextAppearance="@android:style/TextAppearance.DeviceDefault.Large"> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:maxLines="1" android:hint="@string/prompt_password" android:singleLine="true" /></android.support.design.widget.TextInputLayout>
The app is designed to use the new properties provided by the Android Design Support Library package, and a declaration that only needs to introduce the following namespaces on the root element of the layout file.
xmlns:app="http://schemas.android.com/apk/res-auto"
The layout file is set up and works as shown:
From the running results can be seen, the visual effect is significantly better than the mere use of edittext a lot better. Here Textinputlayout did a few things:
- Automatically calculates a padding to allow enough space for animation, error messages, and Word count.
- When EditText gets to the focus, it animates the hint in the EditText to the upper left, avoiding a bad experience when the edittext is used alone, prompting the message to not show when the focus is taken.
- Count EditText words, and dynamically update the display.
In Textinputlayout, there are several important attributes:
- Counterenabled: Whether to enable counters
- Countermaxlength: Maximum word limit when the counter is enabled (only for display)
- Counteroverflowtextappearance: Font format when the number of words exceeds the maximum limit of the counter
- Hintanimationenabled: Whether to enable hint animation effects
- Errorenabled: Whether an error message is displayed
- Errortextappearance: Font format for error messages
Welcome reprint, reproduced at the same time please respect the copyright, attached to the text link: click here
==============================
For more information, please see my blog: Lin Yanjun's blog
==============================
"Advanced article" Android Learning note--textinputlayout