iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android隐藏导航栏和状态栏的方法
  • 897
分享到

Android隐藏导航栏和状态栏的方法

android 2023-09-03 05:09:31 897人浏览 泡泡鱼
摘要

一。去除状态栏 以下是Android去除状态栏的代码示例: 在Activity的onCreate()方法中添加以下代码: getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLS

一。去除状态栏

以下是Android去除状态栏的代码示例:

在Activity的onCreate()方法中添加以下代码:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

在AndroidManifest.xml文件中的Activity节点中添加以下属性:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

注意:这种方法会移除整个状态栏,包括时间、电量等信息。如果只想隐藏状态栏而不影响其他信息,可以使用以下代码:
View decorView = getWindow().getDecorView();
int uioptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getActionBar();
if (actionBar != null) {
    actionBar.hide();
}

这个方法只会隐藏状态栏,而其他信息(如时间、电量等)仍然会显示。

二。导航栏的去除方式

第一种方式:

在Activity的onCreate()方法中添加以下代码:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

在AndroidManifest.xml文件中的Activity节点中添加以下属性:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

注意:这种方法会移除整个导航栏,包括返回键、菜单键等。如果只想隐藏导航栏而不影响其他功能,可以使用以下代码:
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getActionBar();
if (actionBar != null) {
    actionBar.hide();
}

这个方法只会隐藏导航栏,而其他功能(如返回键、菜单键等)仍然会显示。

第二种方式:

在onCreate方法的super.onCreate(savedInstanceState)前面添加getSupportActionBar().hide();就可以了。

来源地址:https://blog.csdn.net/m0_67982986/article/details/131029580

--结束END--

本文标题: Android隐藏导航栏和状态栏的方法

本文链接: https://www.lsjlt.com/news/391666.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作