gpt4 book ai didi

android - stroke 属性不适用于 android studio 中的按钮

转载 作者:行者123 更新时间:2023-12-05 00:15:56 25 4
gpt4 key购买 nike

这是我的 Buttons.xml 文件

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="50dp"/>
<gradient android:startColor="#8E8816"
android:endColor="#145038"
android:angle="270" />
<stroke android:color="#680D0D" android:width="5dp"/>

</shape>

这是我的 activity_main.xml我尝试将 android:background 更改为 android:src 但它也不起作用

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/teal_700"
tools:context=".MainActivity">

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/buttons"
android:text="Button" />
</RelativeLayout>

只有 corners 属性工作正常

不仅笔划没有变化,背景也没有变化我没有得到我做错的地方......任何人都可以帮助我

此处应用背景为 android:background="@drawable/buttons"后按钮的样子 Button_image

最佳答案

发生这种情况是因为如果您使用的是 MaterialComponents 主题和 的默认样式,Button 会自动替换为 MaterialButton > Material 按钮 tints the background使用 colorPrimary

你必须使用:

<Button
android:background="@drawable/buttons"
app:backgroundTint="@null"
... />

enter image description here

关于android - stroke 属性不适用于 android studio 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63789076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com