Esta actividad ya tiene una barra de acción suministrada por la decoración de la ventana


Tratando de mover mis cosas para usar Toolbar en lugar de barra de acción, pero sigo recibiendo un error diciendo

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)

Entonces agregué en mi estilo para que mi actividad no tenga barra de acción

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

Y el tema se aplica a las actividades en mi manifiesto

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

MainActivity extiende GooglePlayServiceActivity así que también establezco el tema allí también

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

Pero todavía recibo el error. Tampoco solicito la función de ventana en ningún lugar. ¿alguna idea de por qué sigo teniendo esto?

Author: Vadim Kotov, 2014-10-22

18 answers

Creo que estás desarrollando para Android Lollipop, pero de todos modos incluir esta línea:

<item name="windowActionBar">false</item> 

A su declaración de tema dentro de su app/src/main/res/values/styles.xml.

Además, si está utilizando AppCompatActivity biblioteca de soporte de la versión 22.1 o superior, agregue esta línea:

<item name="windowNoTitle">true</item>

Su declaración de tema puede verse así después de todas estas adiciones:

<!-- 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>
 667
Author: Nadir Belhaj,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-16 18:35:41

Otra manera fácil es hacer que tu tema sea un hijo de Theme.AppCompat.Light.NoActionBar así:

<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
     ...
</style>
 172
Author: MrEngineer13,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-22 20:47:16

Agregue una sola línea android:theme="@style/AppTheme.NoActionBar" a activity en AndroidManifest y ya lo ha hecho.


AndroidManifest.xml :

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

Styles.xml

<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
</style>
 104
Author: Volodymyr Kulyk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-31 15:30:51

Para usar la barra de herramientas como Barra de acciones, primero deshabilite la Barra de Acciones provista de decoración.

La forma más fácil es hacer que su tema se extienda desde

Tema.AppCompat.NoActionBar

(o su variante ligera).

En segundo lugar, cree una instancia de barra de herramientas, generalmente a través de su XML de diseño:

<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” />

Luego, en tu Actividad o Fragmento, configura la Barra de herramientas para que actúe como tu Barra de Acciones:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.blah);

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

Este código funcionó para mí.

 46
Author: V_J,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-26 22:10:48

Si desea combinar algunas actividades con actionbar y otras no, debe usar el tema base have actionbar enabled y luego crear un subtema que lo usará en actividades que no requieran actionbar

Por ejemplo, puede usar un estilo secundario como este

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

Mientras que el tema base se extiende decir

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

Y luego use el tema no actionbar en el archivo AndroidManifest dentro de la etiqueta de actividad diga

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

Debe aplicar esto a cada actividad individual que no necesita actionbar por lo que si su proyecto requiere menos actividades de la barra de acciones que no, entonces es mejor aplicar esto en el nivel de tema base

 16
Author: Nasz Njoka Sr.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-27 12:13:06

Agregue esto en sus valores/estilos.xml

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

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

</style>

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

</style>

Y agregue el siguiente código en sus valores-v11/styles.xml y valores-v14 / estilos.xml

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

</style>

Eso es todo. Funcionará.

 7
Author: Prabhakaran,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-13 04:54:19

También me enfrenté al mismo problema. Pero usé:

getSupportActionBar().hide();

Antes

setContentView(R.layout.activity_main);

Ahora está funcionando.

Y podemos probar otra opción en el estilo .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>
 6
Author: Thirumalvalavan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-04 07:09:16

Vaya al estilo'.xml ' de su proyecto y hacer windowActionBar a false

<style name="AppCompatTheme" parent="@style/Theme.AppCompat.Light">
        <item name="android:windowActionBar">false</item>
</style>
 5
Author: Asim Krishna Das,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-21 11:55:42

Necesitas cambiar

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

Estas líneas en el manifest.It funcionará perfectamente para mí.

 5
Author: S HemaNandhini,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-16 10:21:47

Agregue esta línea de dos en el tema de su aplicación ubicado en estilo.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

 4
Author: Kailash Dabhi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-04-03 13:40:25

He añadido la barra de herramientas en mi xml. Entonces en mi actividad estaba agregando esta declaración:

setSupportActionBar(toolbar);

Eliminar esto funcionó para mí. Espero que ayude a alguien.

 4
Author: Harry .Naeem,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-06 12:46:31

Si está utilizando Appcompact Actividad utilice estas tres líneas en su tema.

<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowActionBarOverlay">false</item>
 2
Author: Syed Hamza Hassan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-17 04:34:44

En pocas palabras, puedes hacer lo siguiente: -

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));

    }
 1
Author: yash sachdeva,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-04 12:00:16

Así es como resolví el problema. Añadir el siguiente código en su AndroidMainfest.xml

<activity android:name=".YourClass"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">
 </activity>
 1
Author: John Joe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-25 09:15:37

Si obtienes el error en esta línea:

setSupportActionBar(...);

Debe verificar si su actividad se refiere a un tema que contiene una barra de herramientas. Es posible que el AppTheme de tu aplicación ya contenga una barra de herramientas, como

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

Y usted está tratando de añadir una segunda. Si quieres usar el AppTheme de tu aplicación, debes eliminar el tema de tu actividad, en el manifiesto.archivo xml.

Por ejemplo:

<activity
    android:name=".ui.activities.SettingsActivity"
    android:theme="@style/AppTheme1" /> --> remove this theme
 1
Author: live-love,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-04-22 13:26:18

También una versión más corta de un estilo puede ayudar:

<style name="YourActivityTheme" parent="Theme.AppCompat.NoActionBar">
    ...
</style>
 -1
Author: CoolMind,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-19 09:34:02

Simplemente pon parent="Theme.AppCompat.NoActionBar" en tu estilo.archivo xml

Como <style parent="Theme.AppCompat.NoActionBar" name="AppTheme.NoActionBar">

 -1
Author: Md. Ibrahim Shopon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-13 08:33:12

Lo resolví eliminando esta línea:

android:theme="@style/Theme.MyCompatTheme"

De propiedades de actividad en el Manifest file

 -2
Author: Flowra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-18 09:58:43