Nom*_*sta 3 android material-design android-textinputlayout material-components material-components-android
迁移到最新版本的 Material Components ( 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>
Run Code Online (Sandbox Code Playgroud)
现在的问题是,这个输入字段在我的应用程序中看起来很奇怪,具有这种水平填充(对于填充框或轮廓框是必需的)。
所以我的问题是,我怎样才能删除这个填充?
您可以使用以下内容:
<com.google.android.material.textfield.TextInputLayout
....
android:hint="Hint text"
style="@style/My.TextInputLayout.FilledBox.Dense" >
Run Code Online (Sandbox Code Playgroud)
然后您可以使用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>
Run Code Online (Sandbox Code Playgroud)
这里的结果(具有默认样式和自定义样式):
| 归档时间: |
|
| 查看次数: |
749 次 |
| 最近记录: |