How to remove title bar from the android activity?

后端 未结 7 990
名媛妹妹
名媛妹妹 2020-12-23 01:54

Can someone please help me with the issue.I want my activity as full screen and want to remove title from the screen.I have tried several ways but not able to remove it.

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-23 02:34

    In your Android Manifest file make sure that the activity is using this (or a) theme (that is based on) @style/Theme.AppCompat.NoActionBar This removes the ActionBar completely, but won't make your activity fullscreen. If you want to make your activity fullscreen only use this theme

    @android:style/Theme.NoTitleBar.Fullscreen
    

    Or you could change

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    to

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

    This is what I use to get fullscreen at runtime

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    mDecorView = getWindow().getDecorView();
                    mDecorView.setSystemUiVisibility(
                            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                                    | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                                    | View.SYSTEM_UI_FLAG_IMMERSIVE);
                }
    

    To exit fullscreen I use this

    mDecorView = getWindow().getDecorView();
    mDecorView.setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    

提交回复
热议问题