【发布时间】:2016-02-22 04:25:56
【问题描述】:
我按照https://www.bignerdranch.com/blog/splash-screens-the-right-way/ 上的说明为我的应用制作了启动画面,但在我的 background_splash.xml 文件中,代码:
<item android:drawable="@color/gray"/>
返回消息“验证 Android XML 文件中的资源引用”。
我该如何解决这个问题?谢谢!
更新代码:
background_splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/white"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/splash"/>
</item>
</layer-list>
SplashActivity.java:
package PACKAENAME;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="PACKAGENAME">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
</activity>
</application>
</manifest>
【问题讨论】:
-
在不查看其余代码的情况下很难判断哪里出了问题。该博客中的 Github 项目是否运行?
-
@cricket_007 我不确定你到底在问什么,但是当我删除那行代码时,启动页面会运行,只是没有背景颜色。另外,如果您愿意,我可以用我的代码更新问题。
-
是的,请分享 background_splash.xml 的代码
-
该博客有一个指向 Github 的链接以及最终结果。那会运行还是错误仍然发生?除了反复学习之外,没有理由将博客中的所有代码复制粘贴到自己的项目中
-
@CarterRoeser 你在
colors.xml中定义了颜色gray吗?
标签: android colors xml-drawable