【问题标题】:Android error - Failed to find style 'toolbarStyle' in current themeAndroid 错误 - 无法在当前主题中找到样式“toolbarStyle”
【发布时间】:2016-12-19 11:11:21
【问题描述】:

我是 Android 编程新手。目前正在关注一系列 youtube 视频 (https://www.youtube.com/watch?v=Bzh9P1z1l90&list=PLshdtb5UWjSoLy2LPP1FsHi1hwoAS4SBi&index=7) 以了解如何使用 Material Design。

我现在只是停留在某一点上。我收到这样的错误..

我也在谷歌搜索,但没有得到任何可靠的答案。这是我所有的文件。

styles.xml

    <!-- 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="BhramaanTheme" parent="AppTheme"></style>

</resources>

v21/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="BhramaanTheme" parent="AppTheme">
        <item name="android:windowBackground">@color/windowBackground</item>
        <item name="android:navigationBarColor">@color/navigationBarColor</item>
    </style>
</resources>

activity_login.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.bhramaan.android.bhramaan.LoginActivity">

    <include
        android:id="@+id/toolbar"
        layout="@layout/tool_bar"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/toolbar"
        android:text="Hello World!" />
</RelativeLayout>

tool_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    >

</android.support.v7.widget.Toolbar>

AndroidMainfest.xml

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

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

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

</manifest>

LoginActivity.java

package com.bhramaan.android.bhramaan;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

public class LoginActivity extends AppCompatActivity {

    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
    }
}

谁能帮我理解我在这里做错了什么?

问候

【问题讨论】:

  • 您没有在 style.xml 文件中定义 ThemeOverlay.AppCompat.Dark 主题
  • @vinoth12594:感谢您的快速回复。你能帮我理解如何定义那个吗?应将此行 &lt;style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&gt; 替换为 &lt;style name="AppTheme" parent="ThemeOverlay.AppCompat.Dark"&gt; 吗?
  • 你的模拟器 API 级别???
  • 在预览窗口的顶部栏中选择您的 AppTheme

标签: android android-layout android-studio material-design


【解决方案1】:

我认为您必须改用ThemeOverlay.AppCompat.Dark.ActionBar 作为工具栏上的主题叠加层。

【讨论】:

  • 我该怎么做?
【解决方案2】:

替换下面的代码

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
          package="com.bhramaan.android.bhramaan">
    <application
        android:allowBackup="true" 
        android:icon="@mipmap/ic_launcher" 
        android:label="@string/app_name" 
        android:supportsRtl="true" 
        android:theme="@style/BhramaanTheme"> 
        <activity android:name=".LoginActivity"> 
            <intent-filter> 
                <action android:name="android.intent.action.MAIN" /> 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter> 
        </activity> 
    </application> 
</manifest>

【讨论】:

    猜你喜欢
    • 2015-01-15
    • 2017-04-02
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    • 2012-01-20
    • 2012-05-25
    • 2012-03-16
    相关资源
    最近更新 更多