Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crashing when trying to hide the title bar

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>
like image 983
Anis LOUNIS Avatar asked Apr 25 '14 12:04

Anis LOUNIS


People also ask

How do I remove the title bar from my app?

So basically we just need to change DarkActionBar to NoActionBar. NoActionBar theme prevents the app from using the native ActionBar class to provide the app bar. Thus it removes the title of every activity. Another way for removing the title specifically from an activity is by using a getSupportActionBar().

Why does my app keep closing on me?

This usually occurs when your Wi-Fi or cellular data is slow or unstable, causing apps to malfunction. Another reason for Android apps crashing can be a lack of storage space in your device.

Which method must be called to hide the title bar?

Calling the hide() method of ActionBar class hides the title bar.


2 Answers

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.

like image 55
Dhaval Parmar Avatar answered Sep 30 '22 07:09

Dhaval Parmar


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);  
like image 38
Ersin Gülbahar Avatar answered Sep 30 '22 05:09

Ersin Gülbahar