如何从TextInputLayout删除水平填充? [英] How to remove horizontal padding from TextInputLayout?

本文介绍了如何从TextInputLayout删除水平填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在迁移到最新版本的Material Components(1.1.0-alpha09)之后,我注意到TextInputLayout具有一些填充水平填充.我的目标是实现没有背景或轮廓框的旧样式的文本字段.因此,我扩展了其中一种样式,即Widget.MaterialComponents.TextInputLayout.FilledBox并将背景色设置为透明.

After migrating to newest version of Material Components (1.1.0-alpha09), I've noticed that TextInputLayout has some padding horizontal padding. My goal is to achieve the old style of text fields, where there is no background or outline box. So I extended one of the styles, i.e. Widget.MaterialComponents.TextInputLayout.FilledBox and set background color to transparent.

<style name="Widget.MyApp.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
    <item name="boxBackgroundColor">@color/transparent</item>
</style>

现在的问题是,在我的应用中,使用这种水平填充(对于填充或轮廓框是必需的),此输入字段看起来很奇怪.

Now the problem is that this input field looks weird in my app with such horizontal padding (which was necessary for filled or outline box).

所以我的问题是,如何删除该填充物?

So my question is, how can I remove this padding?

推荐答案

您可以使用类似以下内容的

You can use something like:

<com.google.android.material.textfield.TextInputLayout
       ....
       android:hint="Hint text"       
       style="@style/My.TextInputLayout.FilledBox.Dense" >

然后,您可以使用materialThemeOverlay属性定义(要求版本1.1.0)自定义样式:

Then you can define (it requires the version 1.1.0) a custom style using the materialThemeOverlay attribute:

  <style name="My.TextInputLayout.FilledBox.Dense" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
    <item name="materialThemeOverlay">@style/MyThemeOverlayFilledDense</item>
  </style>

  <style name="MyThemeOverlayFilledDense">
    <item name="editTextStyle">@style/MyTextInputEditText_filledBox_dense
    </item>
  </style>

  <style name="MyTextInputEditText_filledBox_dense" parent="@style/Widget.MaterialComponents.TextInputEditText.FilledBox.Dense">
    <item name="android:paddingStart" ns2:ignore="NewApi">4dp</item>
    <item name="android:paddingEnd" ns2:ignore="NewApi">4dp</item>
    <item name="android:paddingLeft">4dp</item>
    <item name="android:paddingRight">4dp</item>
  </style>

这里是结果(具有默认样式和自定义样式):

Here the results (with a default style and the custom style):

这篇关于如何从TextInputLayout删除水平填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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