如何将 padding/margin 添加到 TextInputLayout 中所选菜单选项的左侧?

How do I add padding/margin to the left side of the selected menu option in TextInputLayout?

I have the following exposed dropdown menu that looks like this when an option is selected:

这是我的 XML 布局中显示的下拉菜单的内容:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/drop_down_menu"
    style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginEnd="8dp"
    android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
    app:layout_constraintBottom_toBottomOf="@+id/text_view_1"
    app:layout_constraintEnd_toStartOf="@+id/text_view_2"
    app:layout_constraintTop_toTopOf="@+id/text_view_3">

    <com.google.android.material.textfield.MaterialAutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="none" />

</com.google.android.material.textfield.TextInputLayout>

如何在所选选项的左侧添加space?

感谢 Zain 已经帮助您解决了您的问题,我很乐意在上面添加一些樱桃,以便您将来在添加时轻松决定space 相关查询出现在您的脑海中。

每当我们想要在两个视图之间设置 space 时,我们就会在脑海中想到两个选项 paddingmargin

Padding 用于在视图及其内容之间添加空白 space。

边距用于在两个不同的视图之间添加一个space。

对于填充和边距,我们有两种设置方式,

  • 设置所有边等值
  • 根据要求设置边特定值

具有相等值的所有边:

您可以使用 android:padding="10dp" 设置所有边 10dp 的内边距,android:layout_margin="10dp" 设置所有边 10dp 的边距

具有特定值的边:

填充

  • android:paddingBottom 设置底部边距
  • android:paddingStart 在视图左侧的起始边缘设置填充
  • android:paddingEnd 在视图的右侧设置结束边缘的填充
  • android:paddingTop 设置顶部边距

保证金

  • android:layout_marginBottom 在此视图的底部指定额外的 space。
  • android:layout_marginEnd 在末尾指定额外的 space,表示在该视图的右侧。
  • android:layout_marginStart 在起始侧指定额外的 space,表示在此视图的左侧。
  • android:layout_marginTop 在此视图的顶部指定额外的 space。