问题描述
我有一个带有居中(默认)文本的自定义按钮。我想在此文字的左侧添加8dp的图片,该图片必须位于自定义按钮中。
我只能将其添加为ComponentFactoryResolver
属性。我想使其更加居中。
这是我的自定义按钮。
如何使该图像居中? (文本左侧8dp)
解决方法
只需将MaterialButton
与app:iconGravity
属性一起使用。
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.Icon"
app:icon="@drawable/...."
app:iconGravity="textStart"
android:text="@string/..."
.../>
您可以使用app:iconPadding="xxdp"
属性更改图标和文本之间的填充。
app:iconPadding="0dp"
的示例: