Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 此活动已具有由window decor提供的操作栏_Android_Android Actionbar_Material Design_Android 5.0 Lollipop_Android Toolbar - Fatal编程技术网

Android 此活动已具有由window decor提供的操作栏

Android 此活动已具有由window decor提供的操作栏,android,android-actionbar,material-design,android-5.0-lollipop,android-toolbar,Android,Android Actionbar,Material Design,Android 5.0 Lollipop,Android Toolbar,试图移动我的东西以使用工具栏而不是操作栏,但我一直收到一个错误消息 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tyczj.weddingalbum/com.xxx.xxx.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window dec

试图移动我的东西以使用
工具栏
而不是操作栏,但我一直收到一个错误消息

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tyczj.weddingalbum/com.xxx.xxx.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5039)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
            at android.support.v7.app.ActionBarActivityDelegateBase.setSupportActionBar(ActionBarActivityDelegateBase.java:165)
            at android.support.v7.app.ActionBarActivity.setSupportActionBar(ActionBarActivity.java:92)
            at com.xxx.xxx.MainActivity.onCreate(MainActivity.java:113)
            at android.app.Activity.performCreate(Activity.java:5104)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5039)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
因此,我在我的活动风格中添加了没有actionbar的内容

<style name="AppCompatTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:windowActionBar">false</item>
</style>

假的
主题适用于我清单中的活动

<activity
        android:name=".MainActivity"
        android:windowSoftInputMode="adjustResize|stateHidden"
        android:theme="@style/AppCompatTheme" android:screenOrientation="portrait"/>

MainActivity扩展了GooglePlayServiceActivity,所以我也在那里设置了主题

<activity
       android:name=".GooglePlayServicesActivity"
       android:label="@string/title_activity_google_play_services"
       android:theme="@style/AppCompatTheme">


但我仍然得到了错误。我也不要求任何地方的窗口功能。你知道我为什么还得到这个吗?

我想你是在为Android棒棒糖开发,但无论如何,包括以下内容:

<item name="windowActionBar">false</item> 
<item name="windowNoTitle">true</item>
setSupportActionBar(...);
在添加了所有这些内容之后,您的主题声明可能如下所示:

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

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的
真的

另一个简单的方法是将您的主题设置为
theme.AppCompat.Light.NoActionBar的子主题,如下所示:

<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
     ...
</style>

...

转到项目的“style.xml”,并将windowActionBar设置为false

<style name="AppCompatTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:windowActionBar">false</item>
</style>

假的

我也面临同样的问题。但我用了:

getSupportActionBar().hide()

以前

setContentView(R.layout.activity\u main)

现在它正在工作

我们可以在Style.xml中尝试其他选项

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音

将其添加到您的values/styles.xml中

<style name="YourCustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>

<style name="AppBaseTheme" parent="YourCustomTheme">

</style>

<style name="AppTheme" parent="AppBaseTheme">

</style>
<style name="AppBaseTheme" parent="YourCustomTheme">

</style>

并在values-v11/styles.xml和values-v14/styles.xml中添加以下代码

<style name="YourCustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>

<style name="AppBaseTheme" parent="YourCustomTheme">

</style>

<style name="AppTheme" parent="AppBaseTheme">

</style>
<style name="AppBaseTheme" parent="YourCustomTheme">

</style>


就这样。它会起作用。

要将工具栏用作操作栏,请先禁用装饰提供的操作栏

最简单的方法是将主题从

Theme.AppCompat.NoActionBar

(或其轻型变体)

其次,通常通过布局XML创建工具栏实例:

<android.support.v7.widget.Toolbar
    android:id=”@+id/my_awesome_toolbar”
    android:layout_height=”wrap_content”
    android:layout_width=”match_parent”
    android:minHeight=”?attr/actionBarSize”
    android:background=”?attr/colorPrimary” />

这段代码对我很有用。

如果你想将一些活动与actionbar结合起来,而其他活动没有,你应该使用基本主题启用actionbar,然后创建一个子主题,你可以在不需要actionbar的活动上使用它

<style name="AppCompatTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:windowActionBar">false</item>
</style>
例如,可以使用这样的子样式

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

假的
真的
而基本主题则是

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

然后在活动标记内的AndroidManifest文件中使用非actionbar主题

   <activity
        android:name="com.example.NonActionBarActivity"
        android:theme="@style/AppTheme.NoActionBar"

将单行
android:theme=“@style/AppTheme.NoActionBar”
添加到
AndroidManifest
中的
活动中,您就完成了


AndroidManifest.xml

<activity android:name=".activity.YourActivity"
          android:theme="@style/AppTheme.NoActionBar"><!-- ADD THIS LINE -->


style.xml

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

假的
真的

如果您使用的是
Appcompact
活动,请在主题中使用这三行

<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowActionBarOverlay">false</item>
true
假的
假的

在位于style.xml的应用程序主题中添加这两行内容:-

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

    //Add this two line will fix your problem
    <item name="windowNoTitle">true</item>   <--1(this applies after 22.0.1 support library i think 
    <item name="windowActionBar">true</item> <--2

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
//添加这两行将解决您的问题

真我通过删除这一行解决了这个问题:

android:theme=“@style/theme.MyCompatTheme”


简单地说,您可以从清单文件中的活动属性执行以下操作:-

if (android.os.Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark));

    }

这就是我解决问题的方法。在您的
AndroidMainfest.xml中添加以下代码

<activity android:name=".YourClass"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
 </activity>

您需要更改

  <activity
        android:name=".YOUR ACTIVITY"
        android:theme="@style/AppTheme.NoActionBar" />
</application>`

`

清单中的这些行。它将非常适合我。

我在xml中添加了工具栏。然后在我的活动中,我添加了以下声明:

setSupportActionBar(toolbar);
移除这个对我有用。我希望它能帮助别人。

只需将
parent=“Theme.AppCompat.NoActionBar”
放在style.xml文件中即可


例如-

如果您在这一行中得到错误:

<item name="windowActionBar">false</item> 
<item name="windowNoTitle">true</item>
setSupportActionBar(...);
您需要检查您的活动是否引用了包含工具栏的主题。应用程序的AppTheme可能已经包含工具栏,例如

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

您正在尝试添加第二个。如果要使用应用程序的AppTheme,则需要在manifest.xml文件中从活动中删除该主题

例如:

<activity
    android:name=".ui.activities.SettingsActivity"
    android:theme="@style/AppTheme1" /> --> remove this theme
-->删除此主题

在清单中的应用程序标记内或在活动标记内使用此选项

android:theme=“@style/AppTheme.NoActionBar”


假的
将此更改为NoActionBar
这个对我有用

或只需更改@Style/AppTheme即可

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">


这对我有用

由于内部的custome属性,我得到了这个错误,删除它修复了这个问题

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
..
        <item name="searchBarBgColor">#383838</item>  --> remove this line
    </style>

..
#3838-->删除此行

这也可能是因为您的样式没有指定父级:

<style name="DarkModeTheme" >
    <item name="searchBarBgColor">#D6D6D6</item>
</style>

#D6D6

删除它,它就会解决问题。

非常简单,您只需执行两步中的任何一步即可

  • 将设备显示模式从暗模式更改为正常模式或
  • 在style.xml中,如果使用的是AppCompat,则在主题/样式中添加这两行。
    false-true

  • windowActionBar
    是否与android:windowActionBar
    不同?是的,但是AppCompat stuff查看的是应用程序名称空间属性,而不是android属性。这使得即使在最初没有该属性的平台中也可以指定该属性。这就是它允许像colorPrimary这样的东西进行后移植的方式。当我在我的样式中添加这一行时,应用程序崩溃:(如果您在22.1支持库之后使用AppCompatActivity,也添加true,请不要忘记添加:android:theme=“@style/AppTheme”到清单文件中的应用程序标记。我也尝试了此方法,但仍然出现错误。但是,这可能是在我将主题设置为我的
    GooglePlayServiceActivity
    之前,我不记得了。这是我一直在使用的。请确保