使用新的prefixText时如何更改TextInputLayout的提示填充? [英] How to change hint padding for TextInputLayout when using the new prefixText?

查看:72
本文介绍了使用新的prefixText时如何更改TextInputLayout的提示填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 com.google.android.material:material:1.2.0-alpha02 用新的 prefixText 实现 TextInputLayout .这是一个非常酷的功能,但是当我添加前缀文本时,提示标签会浮起并在前缀之后对齐.这看起来不太好,特别是如果您在同一页面上有更多输入字段而没有前缀,则浮动标签将无法对齐.

我的布局代码的相关部分:

 < LinearLayoutandroid:id ="@ + id/login_input_fields"android:layout_width ="match_parent"android:layout_height ="wrap_content"android:orientation ="vertical">< com.google.android.material.textfield.TextInputLayoutandroid:id ="@ + id/login_username_input"android:layout_width ="match_parent"android:layout_height ="wrap_content"android:hint ="@ string/username_hint"app:prefixText =前缀">< com.google.android.material.textfield.TextInputEditTextandroid: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.TextInputLayoutandroid: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.TextInputEditTextandroid: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> 

解决方案

要使用材料组件库,您必须使用一个

在此主题中使用您的布局:

 < style name ="AppTheme" parent ="Theme.MaterialComponents.DayNight">...</style> 

I have tried implementing TextInputLayout with the new prefixText, using com.google.android.material:material:1.2.0-alpha02. This is a very cool feature, but when I add a prefix text the hint label floats up and aligns after the prefix. This does not look good, especially if you have more input fields on the same page without prefix, the floating labels does not align.

Relevant parts of my layout code:

 <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>

解决方案

To use the Material Components Library you have to use a Theme.MaterialComponents.* theme.

Using your layout with this theme:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
 ...
</style>

Using your layout with this theme:

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
  ...
</style>

这篇关于使用新的prefixText时如何更改TextInputLayout的提示填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆