我有这个 XML 标签:
<Button
android:id="@+id/next"
android:layout_width="305dp"
android:layout_height="64dp"
android:background="@color/colorTheme"
style="@style/ButtonStyle"
android:text="Next"
app:layout_constraintBottom_toTopOf="@+id/imageViewFooterGetStarted"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.968" />
出于某种原因,我的按钮的背景颜色没有改变。我试过只使用 style.xml:
<style name="ButtonStyle" parent="android:Widget.Button">
<item name="android:background">@drawable/btn_get_started</item>
<item name="android:textColor">@color/colorTheme</item>
</style>
并且仍然具有默认的紫色。 android:background
也没有任何影响。
什么可能导致背景颜色不改变?
编辑:我找到了解决方案。结果 android:background
会改变颜色,但前提是使用 <androidx.appcompat.widget.AppCompatButton>
标签而不是 <button>
标签
答案 0 :(得分:0)
尝试使用 AppCompatButtom 而不是 Button
用 AppCompatButtom 替换你的按钮
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/next"
android:layout_width="305dp"
android:layout_height="64dp"
android:background="@color/colorTheme"
style="@style/ButtonStyle"
android:text="Next"
app:layout_constraintBottom_toTopOf="@+id/imageViewFooterGetStarted"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.968" />
希望它能成功!!