图标未出现在 MaterialButton android 工作室中
Icon is not appearing in the MaterialButton android studio
我正在将 MaterialButton
添加到我的 android 项目中,它只显示文本而不是文本和图标,这是我的代码:
<com.google.android.material.button.MaterialButton
android:id="@+id/homeBtn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:textAllCaps="true"
android:textColor="#F8F8F8"
android:background="#3F51B5"
android:text="@string/findTrans"
app:icon="@drawable/white_bus_icon"
app:iconGravity="textStart"
app:iconTint="@null"
app:layout_constraintBottom_toTopOf="@+id/button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2"
/>
按钮的外观如下:
删除行
app:iconTint="@null"
再试一次
基于 我发现我只需要将这些行添加到我的应用程序样式文件中
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
当然,在将依赖项添加到您的 Gradle 文件之后:
implementation 'com.google.android.material:material:1.0.0'
我正在将 MaterialButton
添加到我的 android 项目中,它只显示文本而不是文本和图标,这是我的代码:
<com.google.android.material.button.MaterialButton
android:id="@+id/homeBtn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:textAllCaps="true"
android:textColor="#F8F8F8"
android:background="#3F51B5"
android:text="@string/findTrans"
app:icon="@drawable/white_bus_icon"
app:iconGravity="textStart"
app:iconTint="@null"
app:layout_constraintBottom_toTopOf="@+id/button2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2"
/>
按钮的外观如下:
删除行 app:iconTint="@null" 再试一次
基于
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light">
当然,在将依赖项添加到您的 Gradle 文件之后:
implementation 'com.google.android.material:material:1.0.0'