0

how to hide title bar from Android ActionBarActivity I have tried everything but did not get success.

getting that Exception :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dan.msdashboard/com.dan.msdashboard.FirstActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

but I am using this code

protected void onCreate(Bundle savedInstanceState) {
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);

        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

            // Hide the Title bar of this activity screen


        this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_simple);

Please help me solve .

Thanks in advance....

paras kochar
  • 29
  • 1
  • 1
  • 7

5 Answers5

1

Once try as follows

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

        // Hide the Title bar of this activity screen
    this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_simple);

hope this will helps you.

Nagaraju V
  • 2,739
  • 1
  • 14
  • 19
0

Do feature before onCreate

protected void onCreate(Bundle savedInstanceState) {
        // requestWindowFeature(Window.FEATURE_NO_TITLE);

  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);


        super.onCreate(savedInstanceState);



            // Hide the Title bar of this activity screen


        this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_simple);
Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
0

Set the window flags before calling super.onCreate():

protected void onCreate(Bundle savedInstanceState) {
        getWindow()...
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple);
}
natario
  • 24,954
  • 17
  • 88
  • 158
0

try this code

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
    }
}
Ravi Makvana
  • 2,872
  • 2
  • 24
  • 38
0

In your AndroidManifest.xml

If you are using AppCompat

add one attribute in the activity tag to hide ActionBar

android:theme="@style/Theme.AppCompat.NoActionBar"
NarenderNishad
  • 1,058
  • 1
  • 17
  • 31