如何减少文本提示和文本行之间的填充? [英] How do I reduce the padding between the text hint and text line?

查看:114
本文介绍了如何减少文本提示和文本行之间的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示了提示的TextInputEditText.我真的不喜欢提示和文本行之间的空间量.我尝试将重力设置为最低,但没有运气.

I have a TextInputEditText with a hint shown. I really do not like the amount of space between the hint and text line. I have tried setting the gravity to bottom but no luck.

       <com.google.android.material.textfield.TextInputEditText
                    android:layout_width="400dp"
                    android:layout_height="wrap_content"
                    android:background="@android:color/white"
                    android:inputType="textNoSuggestions"
                    android:hint="@string/email_hint"
                    android:textColorHint="@color/color_hint_grey"
                    android:fontFamily="@font/alternate_got_no1d"
                    android:textSize="20sp"/>

推荐答案

为了减小文本框的高度,可以使用

In order to reduce the height of a text box, you can use a dense style, which will reduce the vertical padding within the text box

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

否则,您可以使用以下方式定义(要求版本1.1.0)自定义样式:

Otherwise you can define (it requires the version 1.1.0) a custom style using:

  <style name="MyDense" 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:paddingTop">24dp</item>
    <item name="android:paddingBottom">4dp</item>
  </style>

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

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

这篇关于如何减少文本提示和文本行之间的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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