How to remove horizontal padding from TextInputLayout?

前端 未结 1 1868
孤城傲影
孤城傲影 2021-01-20 03:43

After migrating to newest version of Material Components (1.1.0-alpha09), I\'ve noticed that TextInputLayout has some padding horizontal padding. M

相关标签:
1条回答
  • 2021-01-20 04:43

    You can use something like:

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

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

    0 讨论(0)
提交回复
热议问题