【问题标题】:I am having errors in styles.xml in app theme我在应用主题中的 styles.xml 中有错误
【发布时间】:2017-12-02 07:00:33
【问题描述】:

这是我的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sammar.materialdeisgn">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme.NoActionBar">
    <activity
        android:name=".MainActivity"
        android:label="YourAppName"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
 </application>

</manifest>

这是我的styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

我收到以下错误:

1)Error:No resource found that matches the given name (at 'theme' with value '@style/AppTheme.NoActionBar').



 2)Error:No resource found that matches the given name (at 'theme' with value '@style/AppTheme.NoActionBar').



 3)Error:No resource found that matches the given name (at 'theme' with value '@style/AppTheme.NoActionBar').



 4)Error:No resource found that matches the given name (at 'theme' with value '@style/AppTheme.NoActionBar').



 5)Error:Execution failed for task ':app:processDebugResources'.



 > com.android.ide.common.process.ProcessException: Failed to execute 

aapt

【问题讨论】:

    标签: android xml android-manifest android-styles


    【解决方案1】:

    您的清单样式未引用NoActionBar 主题,因此添加以下行

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    

    所以你的Style.xml 看起来像

    <resources>
    
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    </resources>
    

    【讨论】:

    • 它工作了..但我不明白是什么问题。?
    • @SammarAhmad 你知道如何在 StackOverflow 上接受答案吗?
    • @SammarAhmad 检查此链接meta.stackexchange.com/a/5235/376420
    【解决方案2】:

    尝试使用:

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    

    因为可能是您的应用使用 name="AppTheme"。就这样。

    【讨论】:

      【解决方案3】:

      您已经在样式中声明了 No action Bar,然后在清单中不需要,只需在清单中使用

       <activity
                  android:name=".MainActivity"
                  android:label="YourAppName"
                  android:theme="@style/AppTheme">
      

      【讨论】:

        猜你喜欢
        • 2013-05-01
        • 1970-01-01
        • 2016-07-24
        • 1970-01-01
        • 1970-01-01
        • 2015-09-23
        • 2012-12-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多