当为 Activity 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
的样子
如何让 drawableLeft
与 Base.Theme.MaterialComponents
主题一起工作?
最佳答案
只需使用 MaterialButton
使用 app:icon
属性:
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
app:icon="@drawable/ic_add_24px"
../>
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.Icon"
app:icon="@drawable/ic_add_24px"
../>
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
app:icon="@drawable/ic_add_24px"
../>
使用 app:iconGravity
来配置 start|end|textStart|textEnd
。
<com.google.android.material.button.MaterialButton
app:iconGravity="end"
../>
关于android - drawableLeft/Right 等不适用于 Theme.MaterialComponents,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58083679/