Search code examples
javaandroidtitlebar

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


Solution

  • 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"