App crashing when trying to hide the title bar
Asked Answered
D

5

8

In order to make a full screen app, I've done the following changes to the manifest of a new "blank activity" project:

  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

The application crashes when running on any device. The changes I've made have been recommended by many posts here in StackOverflow and I couldn't figure out what I've done wrong.

Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    <activity
        android:name="com.example.app.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
 </application>
</manifest>
Down answered 25/4, 2014 at 12:45 Comment(3)
Can you please post your whole AndroidManifest.xml and the logcat?Absalom
crash = stack trace. post itMarinelli
possible duplicate of Android Theme.NoTitleBar doesnot workFireside
W
15

Just do below way:

import android.support.v7.app.ActionBarActivity;

extend:

    public class SplashScreen extends ActionBarActivity {

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getSupportActionBar().hide();
            setContentView(R.layout.splash_screen);
    }
}

Its working fine with API level 7 or higher.

EDIT:

Use AppCompatActivity because ActionBarActivity @deprecated in API 23.

Wera answered 26/4, 2014 at 7:12 Comment(0)
C
1

You can do it programmatically like this:(do not need edit your manifest file if you are using this)

 super.onCreate(savedInstanceState);
       setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.main);  
Caneghem answered 25/4, 2014 at 12:51 Comment(0)
U
0

in order to show your app in full screen use the following code in style.xml file in res-->values-->styles.xml

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

OR ELSE use the Window Manager in programming code of each activity that are mentioned in Android Manifest file as like below...

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Unmake answered 25/4, 2014 at 12:53 Comment(1)
did you clean your project?Caneghem
A
0

Include this in your manifest file. It will work.

android:theme="@android:style/Theme.NoTitleBar"
Argyle answered 25/4, 2014 at 12:59 Comment(3)
See clearly my answer. Its different from what you are using.Argyle
You are using android:theme="@android:style/Theme.NoTitleBar.Fullscreen" instead use this android:theme="@android:style/Theme.NoTitleBar"Argyle
@AnixPasBesoin you need to post the stacktrace. the crash could be bcoz of a different reasonLierne
R
-1
try
        {
            this.getSupportActionBar().hide();
        }
        catch (NullPointerException e){}

        setContentView(R.layout.activity_main);

this worked for me, try this!

Refute answered 30/4, 2020 at 9:42 Comment(1)
package com.example.casser; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.Window; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { this.getSupportActionBar().hide(); } catch (NullPointerException e){} setContentView(R.layout.activity_main); } }Refute

© 2022 - 2024 — McMap. All rights reserved.