Hide tittle bar in ActionBarActivity using java code

120 views Asked by At

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....

5

There are 5 answers

0
Murtaza Khursheed Hussain On BEST ANSWER

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);
0
natario On

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

protected void onCreate(Bundle savedInstanceState) {
        getWindow()...
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple);
}
0
Nagaraju V On

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.

0
Ravi Makvana On

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();
    }
}
0
NarenderNishad On

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"