是否有隐藏导航栏的xml方式?

问题描述 投票:1回答:3

为了隐藏导航栏,android docs提供了以下解决方案:

   View decorView = getWindow().getDecorView();
   int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                 | View.SYSTEM_UI_FLAG_FULLSCREEN;
   decorView.setSystemUiVisibility(uiOptions);

有没有基于XML的方法来做到这一点?我在风格和操作方式中尝试了以下方式:

  <activity
      android:name=".MainActivity"
      android:label="@string/title_activity_main"
      android:theme="@style/AppTheme.NoActionBar" />

   <style name="AppTheme.NoActionBar">
       <item name="windowActionBar">false</item>
       <item name="windowNoTitle">true</item>
   </style>

但这似乎不起作用。

也许我可以在我的活动的XML中执行上述解决方案?

android xml
3个回答
2
投票

您可以在styles.xml中覆盖Base App主题

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
</style>

并将此主题添加到您的清单中,例如

<application
        android:theme="@style/AppTheme">

0
投票

设置导航视图的属性如下。

 android:visibility="gone"

要么

 android:visibility="invisible"

隐形意味着你看不到布局,但它就在那里。

并且Gone意味着视图已经消失,您无法通过触摸访问它。


0
投票
 <com.google.android.material.navigation.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true">

在xml文件中,这是navigationview的代码

如果你想以编程方式设置可见性而不是使用like

navigationview.setvisibility(View.INVIBLE);
© www.soinside.com 2019 - 2024. All rights reserved.