Android去除頂部導航條


目錄

去除標題欄

去除狀態欄和標題欄

去除標題欄

經過,今天項目需要去除頂部導航條,查了很多,總結一下就是2種情況

第一種:使用requestWindowFeature(Window.FEATURE_NO_TITLE);,前提要求是必須在Activity下

但是這個項目,我是使用Fragement,里面有一個方法getSupportFragmentManager();在Activity下無法使用,頭都要禿了

第二種:在styles.xml中將AppTheme里面的參數parent改為Theme.AppCompat.Light.NoActionBar

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

效果圖

 

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------

網上還有一種教程在AppCompatActivity下可以使用的方法,但是親測無用

    protected void onCreate(Bundle savedInstanceState) {
        //去掉系統狀態欄
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maincontainer);
        initView();
    }

 去除標題欄和狀態欄

在res/value/styles.xml中添加下面的style

    <!-- 去除頂部的狀態欄和標題欄-->
    <style name="NoTitle" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>

 

在AndroidManifest.xml中調用該style

 

效果圖

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM