Mattia
Mattia

Reputation: 329

Android: remove title bar error

Hello i'm trying to remove the title bar from my app with this code:

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

Under the onCreate method in the activity, but when i run the app it gives error and it closes (i'm sorry but i don't know how to see the error log).

Why it gives error? Thanks

Upvotes: 1

Views: 356

Answers (5)

Nufail Achath
Nufail Achath

Reputation: 58

Solution 1.

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (getSupportActionBar() != null) {
               getSupportActionBar().hide();
    }

    setContentView(R.layout.activity_main);

}

Solution 2.

Maybe the problem is due to your app theme. So check your activity type ( Appcompact Activity, ListActivity), Depend on the activity change theme for activity like this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.No_Title_AppTheme);
}

In style.xml:

<resources>

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

    </style>
    <style name="No_Title_AppTheme" parent="android:Theme.Light.NoTitleBar">

    </style>
</resources>

Upvotes: 1

Ahmad Aghazadeh
Ahmad Aghazadeh

Reputation: 17131

You must call requestWindowFeature(Window.FEATURE_NO_TITLE); before setContentView().

@Override
protected void onCreate(
    final Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);


    getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main);


}

If you want to remove the title, just add this style into your manifest file.

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

Upvotes: 2

user3269550
user3269550

Reputation: 474

try this

Write this lines before setcontentview your activity will be full screen

requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

Upvotes: 1

Hiren Patel
Hiren Patel

Reputation: 52790

You have 2 ways to do this:

  1. Simply you must use Activity instead of Appcompactactivity.

Or

  1. Add getActionBar.hide() instead of requestWindowFeature(Window.FEATURE_NO_TITLE); if you use Appcompactactivity

Hope this would help you.

Upvotes: 1

Jas
Jas

Reputation: 3212

Add requestWindowFeature(Window.FEATURE_NO_TITLE); before setContentView()

like:

requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity);

Upvotes: 1

Related Questions