material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.42k stars 3.08k forks source link

[MaterialTextField] Could there be customizable inner-horizontal-padding in MaterialTextField when start/end icon is shown? #2651

Closed EinNarr closed 2 years ago

EinNarr commented 2 years ago

Is your feature request related to a problem? Please describe. Although the paddings of the EditText is editable, they are overwritten by code when start/end icon is shown. If I modify the shape of the TextField box, the positioning of the icon could be too close to the edge when the corner size gets larger.

Describe the solution you'd like May I kindly ask for attributes that could control the padding with icons? Or maybe make the calculation in the java code relevant with the padding set on the EditText?

Describe alternatives you've considered Maybe make the whole start/end-icon layout customizable?

dsn5ft commented 2 years ago

I think this is a duplicate of https://github.com/material-components/material-components-android/issues/366. Can you try the workarounds mentioned there for now? (Finding the icon view and setting margins on it)

EinNarr commented 2 years ago

I am afraid it is not a handy way in my case. I am trying to provide a modified style set upon M3 styles to all my teams to give all our apps a unified appearance. I would have to make it a new class inheriting TextInputLayout, all telling my collegues to set a margin before use.

dsn5ft commented 2 years ago

Would you be able to try this workaround?

  <style name="Widget.MyApp.TextInputLayout.OutlinedBox" parent="Widget.Material3.TextInputLayout.OutlinedBox">
    <item name="materialThemeOverlay">@style/ThemeOverlay.MyApp.TextInputEditText.OutlinedBox</item>
  </style>

  <style name="ThemeOverlay.MyApp.TextInputEditText.OutlinedBox" parent="ThemeOverlay.Material3.TextInputEditText.OutlinedBox">
    <item name="imageButtonStyle">@style/Widget.MyApp.TextField.ImageButton</item>
  </style>

  <style name="Widget.MyApp.TextField.ImageButton" parent="Widget.AppCompat.ImageButton">
    <item name="android:paddingLeft">8dp</item>
    <item name="android:paddingRight">8dp</item>
  </style>

It will add an extra 8dp of padding to both the start and end icons.

wiryadev commented 1 year ago

I think this is a duplicate of #366. Can you try the workarounds mentioned there for now? (Finding the icon view and setting margins on it)

it doesn't work, the 4dp margin will always be there