【问题标题】:Error when changing the color of android apps background更改android应用程序背景颜色时出错
【发布时间】:2017-01-05 14:15:08
【问题描述】:

当我使用普通颜色作为我的应用的背景时,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"/>

【问题讨论】:

  • 你能发布你如何在你的xml-s中使用渐变背景吗?
  • 在您的应用崩溃时分享您的 LogCat。
  • @AhlemJarrar apk 成功构建,但是当我尝试在我的设备上运行应用程序时,应用程序崩溃了

标签: android xml colors background gradient


【解决方案1】:

在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"

【讨论】:

  • 我的代码和你一样,当我构建 apk 时。 apk 成功构建。但是当我在我的设备上打开应用程序时,应用程序崩溃了
猜你喜欢
  • 1970-01-01
  • 2011-02-14
  • 2021-04-02
  • 1970-01-01
  • 1970-01-01
  • 2012-07-14
  • 1970-01-01
  • 2014-11-08
  • 2018-11-10
相关资源
最近更新 更多