问题描述
我在我的 XML 活动中创建了一个 ImageButton,但它与暗模式不匹配。背景和图像的颜色仍然与正常模式相同。 我正在为这个 ImageButton 和其他 Button 使用一个形状,我在使用 Button 时没有问题。
这是我的代码:
<ImageButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@drawable/roundedbutton"
android:contentDescription="@string/actionButtonDescription"
android:padding="10dp"
android:src="@drawable/ic_baseline_add_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
这里是我的形状“roundedbutton.xml :
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@color/primaryColor"/>
<corners
android:bottomrighTradius="200dp"
android:bottomLefTradius="200dp"
android:topRighTradius="200dp"
android:topLefTradius="200dp"/>
我需要添加一些参数吗?
解决方法
尝试在您的 ImageButton
标记中添加以下行:
android:tint="#0000ffff"
这里的代码 #0000ffff
用于透明颜色。