【发布时间】:2021-05-28 06:59:09
【问题描述】:
好的,所以我的按钮没有显示应有的渐变(渐变没有显示,它只是正常的颜色背景),我知道为什么会这样,一切看起来都应该是我的样子,有人可以接受吗看看:
activity_main.xml
...
<Button
android:id="@+id/button1"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="@drawable/button"
app:icon="@drawable/ic_baseline_room_service_24"
android:fontFamily="monospace"
android:padding="15dp"
android:paddingEnd="40dp"
android:text="BROWSE BY INGREDIENTS"
android:textColor="#FFFFFF"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.084"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/viewPager"
app:layout_constraintVertical_bias="0.396" />
...
这是布局中显示的按钮照片: button (gradient not working)
button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#1746D3"
android:endColor="#6D34CF"/>
<corners
android:bottomRightRadius="900dp"
android:radius="90dp"/>
</shape>
</item>
</selector>
这是渐变背景的照片:gradient
但是,android:background="..." 确实在侧面显示了迷你预览:button_preview
如有任何帮助,我们将不胜感激!
【问题讨论】:
-
您使用的是 Material 主题吗? Material Buttons 不支持渐变或自定义背景,它们只支持不同的颜色
backgroundTint -
@TorkelVelure 不,我没有使用 Material Button... 没关系,@MarcoNardelotto 的答案对我有用,即将
Button更改为AppCompatButton