美文网首页
Android Button设置Background无效不起作用

Android Button设置Background无效不起作用

作者: Lee坚武 | 来源:发表于2021-06-28 14:49 被阅读0次
Android Button设置Background无效不起作用问题,我在代码上创建按钮是这样子的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".HomeMenuActivity"
    android:background="@mipmap/home_page"
    android:padding="20dp"
    android:orientation="vertical">

    <Button
        android:id="@+id/home_btn1"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_marginTop="180dp"
        android:background="@mipmap/btn_food_list"
        android:onClick="onClick" >
    </Button>

图片资源也没有问题,存在的

解决方法:在res/values/themes.xml 中,将<style name="Theme.Healthy" parent="Theme.MaterialComponents.DayNight.NoActionBar">改为

<style name="Theme.Healthy" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge">就可以了

image.png

相关文章

网友评论

      本文标题:Android Button设置Background无效不起作用

      本文链接:https://www.haomeiwen.com/subject/dpmqultx.html