How to remove title bar from the android activity?

后端 未结 7 923
名媛妹妹
名媛妹妹 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);
    
    0 讨论(0)
  • 2020-12-23 02:36

    Try this:

    this.getSupportActionBar().hide();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        try
        {
            this.getSupportActionBar().hide();
        }
        catch (NullPointerException e){}
    
        setContentView(R.layout.activity_main);
    }
    
    0 讨论(0)
  • 2020-12-23 02:36

    you just add this style in your style.xml file which is in your values folder

    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>
    

    After that set this style to your activity class in your AndroidManifest.xml file

    android:theme="@style/AppTheme.NoActionBar"
    

    Edit:- If you are going with programmatic way to hide ActionBar then use below code in your activity onCreate() method.

    if(getSupportedActionbar()!=null)    
         this.getSupportedActionBar().hide();
    

    and if you want to hide ActionBar from Fragment then

    getActivity().getSupportedActionBar().hide();
    

    AppCompat v7:- Use following theme in your Activities where you don't want actiobBar Theme.AppComat.NoActionBar or Theme.AppCompat.Light.NoActionBar or if you want to hide in whole app then set this theme in your <application... /> in your AndroidManifest.

    In Kotlin:

    add this line of code in your onCreate() method or you can use above theme.

    if (supportActionBar != null)
            supportActionBar?.hide()
    

    i hope this will help you more.

    0 讨论(0)
  • 2020-12-23 02:39

    Add this two line in your style.xml

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    
    0 讨论(0)
  • 2020-12-23 02:42

    You just add following lines of code in style.xml file

    <style name="AppTheme.NoTitleBar" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    

    change apptheme in AndroidManifest.xml file

    android:theme="@style/AppTheme.NoTitleBar"
    
    0 讨论(0)
  • 2020-12-23 02:54

    Add in activity

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    and add your style.xml file with the following two lines:

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    
    0 讨论(0)
提交回复
热议问题