drawableLeft / Right и т. д. не работает с Theme.MaterialComponents - PullRequest
1 голос
/ 24 сентября 2019

При использовании темы для действия Theme.MaterialComponents...., если я хочу использовать drawableLeft/Right и т. Д. С кнопкой, они не отображаются.Но если я использую тему Base.Theme.AppCompat, они работали как положено.Вот кнопка:

       <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Test Button"
            android:drawableLeft="@drawable/ic_envelope"/>

И вот как это выглядит с темой Base.Theme.MaterialComponents enter image description here

И это с Base.Theme.AppCompat enter image description here

Как заставить drawableLeft работать с Base.Theme.MaterialComponents темой?

1 Ответ

2 голосов
/ 24 сентября 2019

Просто используйте MaterialButton с атрибутом app:icon:

<com.google.android.material.button.MaterialButton
      style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
      app:icon="@drawable/ic_add_24px"
      ../> 

Screenshot of an outlined button with an icon

<com.google.android.material.button.MaterialButton
    style="@style/Widget.MaterialComponents.Button.Icon"
    app:icon="@drawable/ic_add_24px"
    ../>

Screenshot of a filled button with an icon

<com.google.android.material.button.MaterialButton
    style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
    app:icon="@drawable/ic_add_24px"
    ../>

Screenshot of a borderless button with an icon

Использование app:iconGravity для настройки start|end|textStart|textEnd.

<com.google.android.material.button.MaterialButton
    app:iconGravity="end"
    ../>

enter image description here

...