【问题标题】:@color/gray “Validates resource references inside Android XML files”@color/gray “验证 Android XML 文件中的资源引用”
【发布时间】: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


【解决方案1】:

在您的 color.xml 中为颜色添加价值,如下所示

 <color name="grey">#6E6E6E</color>

【讨论】:

    【解决方案2】:

    我不是安卓开发者,所以当正确答案说是

    在您的 color.xml 中为颜色添加价值,如下所示

    我不知道那是什么意思。

    这意味着什么。转到您的 android 应用程序中的此路径

    app/src/main/res/values/
    

    并创建或使用名为“colors.xml”的文件。然后将灰度值添加到它(或您需要的任何其他颜色值)

    <?xml version="1.0" encoding="utf-8"?>
        <resources>
            <color name="grey">#6E6E6E</color>
        </resources>
    

    使用自定义颜色时请务必使用

    <item android:drawable="@color:grey" />
    

    代替安卓颜色

    <item android:drawable="@android:color/custom_color" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-10
      • 2013-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多