繁体   English   中英

更改android应用背景颜色时出错

[英]Error when changing the color of android apps background

当我使用普通颜色作为应用程序的背景时,apk会成功构建,并且应用程序可以在我的设备上完美运行。

问题是,当我将背景更改为渐变色背景时,apk成功构建,但应用程序在我的设备上崩溃。

<ImageButton android:id="@+id/renunganbutton"
             android:layout_width="match_parent" 
             android:layout_height="wrap_content" 
             android:layout_weight="3" 
             android:background="#212326" 
             android:src="@drawable/renungan"/>

在drawable文件夹中创建一个xml文件,例如gradient.xml ,然后尝试编写以下代码:

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<gradient
    android:startColor="#000000"
    android:centerColor="#5b5b5b"
    android:endColor="#000000"
    android:angle="0" />

可能的角度是:

0、90、180、270

然后像这样在MainActivity.xml中设置元素的背景:

android:background="@drawable/gradient.xml"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM