How to hide the title bar? Crash when changing android:Theme="@style/Apptheme"

Asked

Viewed 616 times

2

I’m breaking my head here to hide the bar that gives the name of the app... I’ve tried everything I’ve seen on the Internet, nothing works... and when I change the android:theme="@style/AppTheme" for android:theme="@android:style/Theme.NoTitleBar" the application stops working I do not understand for what reason, so what I have done so far is to change the java file to hide the title bar, tamper with Styles.xml to hide the title bar. My minimum API is 15 (Android 4.0.3)

Androidmanifest:

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

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

</manifest>

Styles:

<resources>

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

        <!-- Customize your theme here. -->
        <item name="android:windowNoTitle">true</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

Activity:

package com.knautiluz.feralbytes;

import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //Tudo que ocorre no inicio do app > Fica em tela cheia
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

CRASH:

--------- Beginning of crash

06-26 23:13:44.705 2373-2373/com.knautiluz.feralbytes E/Androidruntime: FATAL EXCEPTION: main Process: com.knautiluz.feralbytes, PID: 2373 java.lang.Runtimeexception: Unable to start Activity Componentinfo{com.knautiluz.feralbytes/com.knautiluz.feralbytes.Mainactivity}: java.lang.Illegalstateexception: You need to use a Theme.Appcompat Theme (or Descendant) with this Activity. at android.app.Activitythread.performLaunchActivity(Activitythread.java:2416) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2476) at android.app.Activitythread. -wrap11(Activitythread.java) at android.app.Activitythread$H.handleMessage(Activitythread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.Activitythread.main(Activitythread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:726) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:616) Caused by: java.lang.Illegalstateexception: You need to use a Theme.Appcompat Theme (or Descendant) with this Activity. at android.support.v7.app.Appcompatdelegateimplv7.createSubDecor(Appcompatdelegateimplv7.java:343) at android.support.v7.app.Appcompatdelegateimplv7.ensureSubDecor(Appcompatdelegateimplv7.java:312) at android.support.v7.app.Appcompatdelegateimplv7.setContentView(Appcompatdelegateimplv7.java:277) at android.support.v7.app.Appcompatactivity.setContentView(Appcompatactivity.java:140) at com.knautiluz.feralbytes.MainActivity.onCreate(Mainactivity.java:15) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.Activitythread.performLaunchActivity(Activitythread.java:2369) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2476)  at android.app.Activitythread. -wrap11(Activitythread.java)  at android.app.Activitythread$H.handleMessage(Activitythread.java:1344)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.Activitythread.main(Activitythread.java:5417)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:726)  at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:616)

I would like to know first what causes this crash when changing the android:theme="@style/AppTheme" for `android:Theme="@android:style/Theme.Notitlebar"

  • Can log the error that occurs?

  • @Marcogiovanni Ready put! I think it’s this log...

  • I don’t know if it helps, but I’m using Empty Activity by default

3 answers

3


Do so.

<style name="CustomBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
       <item name="windowActionBar">false</item>
</style>

Answering your question is that you are using Appcompatactivity and style @android:style/Theme.NoTitleBar is not compatible with it. Good guess that’s it. If you read the error message it says so You need to use a Theme.AppCompat theme (you need to use a Theme.Appcompat theme).

  • That’s right, thank you!

1

Just do this in Styles.

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

    <item name="colorPrimary">@color/SuaCor1</item>
    <item name="colorPrimaryDark">@color/SuaCor2</item>
    <item name="colorAccent">@color/SuaCor3</item>

</style>

1

Create a theme based on Theme.AppCompat.Light

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

and in its manifesto

android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"

Reference:link

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.