Android Button设置Background无效不起作用

2021-06-28  本文已影响0人  Lee坚武
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
上一篇 下一篇

猜你喜欢

热点阅读