我尝试过实施TextInputLayout
与新的prefixText
, using com.google.android.material:material:1.2.0-alpha02
。这是一个非常酷的功能,但是当我添加前缀文本时,提示标签会向上浮动并在前缀之后对齐。这看起来不太好,特别是如果同一页面上有更多没有前缀的输入字段,浮动标签不会对齐。
我的布局代码的相关部分:
<LinearLayout
android:id="@+id/login_input_fields"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_username_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username_hint"
app:prefixText="Prefix">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/login_username_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_password_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:imeOptions="actionDone"
app:endIconMode="password_toggle">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password_hint"
android:inputType="textPassword"
android:singleLine="true"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
要使用材料组件库,您必须使用 a Theme.MaterialComponents.* theme https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#4-change-your-app-theme-to-inherit-from-a-material-components-theme.
将您的布局与此主题一起使用:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
</style>
将您的布局与此主题一起使用:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
...
</style>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)