如何从 TextInputLayout 中删除水平填充?
How to remove horizontal padding from TextInputLayout?
迁移到最新版本的 Material 组件 (1.1.0-alpha09
) 后,我注意到 TextInputLayout
有一些水平填充。我的目标是实现没有背景或轮廓框的旧式文本字段。所以我扩展了其中一种样式,即 Widget.MaterialComponents.TextInputLayout.FilledBox
并将背景颜色设置为透明。
<style name="Widget.MyApp.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
<item name="boxBackgroundColor">@color/transparent</item>
</style>
现在的问题是这个输入字段在我的应用程序中看起来很奇怪,有这样的水平填充(这是填充框或轮廓框所必需的)。
所以我的问题是,如何删除此填充?
您可以使用类似的东西:
<com.google.android.material.textfield.TextInputLayout
....
android:hint="Hint text"
style="@style/My.TextInputLayout.FilledBox.Dense" >
然后可以使用materialThemeOverlay
属性定义(需要1.1.0版本)自定义样式:
<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>
这里是结果(使用默认样式和自定义样式):
迁移到最新版本的 Material 组件 (1.1.0-alpha09
) 后,我注意到 TextInputLayout
有一些水平填充。我的目标是实现没有背景或轮廓框的旧式文本字段。所以我扩展了其中一种样式,即 Widget.MaterialComponents.TextInputLayout.FilledBox
并将背景颜色设置为透明。
<style name="Widget.MyApp.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.Dense">
<item name="boxBackgroundColor">@color/transparent</item>
</style>
现在的问题是这个输入字段在我的应用程序中看起来很奇怪,有这样的水平填充(这是填充框或轮廓框所必需的)。
所以我的问题是,如何删除此填充?
您可以使用类似的东西:
<com.google.android.material.textfield.TextInputLayout
....
android:hint="Hint text"
style="@style/My.TextInputLayout.FilledBox.Dense" >
然后可以使用materialThemeOverlay
属性定义(需要1.1.0版本)自定义样式:
<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>
这里是结果(使用默认样式和自定义样式):