当前位置:首页 » 安卓系统 » android隐藏显示状态栏

android隐藏显示状态栏

发布时间: 2023-08-28 20:12:36

㈠ Android 完全隐藏状态栏方法

Android 完全隐藏状态栏方法  https://blog.csdn.net/ljbphoebe/article/details/88179576

1. 隐藏ActionBar:

ActionBar actionBar = getActionBar();

if (actionBar != null) {

    actionBar.hide();

}

如果是继承AppCompatActivity,就用getSupportActionBar()。

2. 隐藏状态栏

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

通过这两个步就可以全屏显示启动页了。

然而,当开始动态申请权限,弹出系统的权限提示对话框后,状态栏又重新露出来了。我日,不是隐藏了吗?怎么又出来了,什么鬼?

通过查看源码的解释:

/**

* Request that the visibility of the status bar or other screen/window

* decorations be changed.

*

* <p>This method is used to put the over device UI into temporary modes

* where the user's attention is focused more on the application content,

* by dimming or hiding surrounding system affordances.  This is typically

* used in conjunction with {@link Window#FEATURE_ACTION_BAR_OVERLAY

* Window.FEATURE_ACTION_BAR_OVERLAY}, allowing the applications content

* to be placed behind the action bar (and with these flags other system

* affordances) so that smooth transitions between hiding and showing them

* can be done.

*

* <p>Two representative examples of the use of system UI visibility is

* implementing a content browsing application (like a magazine reader)

* and a video playing application.

*

* <p>The first code shows a typical implementation of a View in a content

* browsing application.  In this implementation, the application goes

* into a content-oriented mode by hiding the status bar and action bar,

* and putting the navigation elements into lights out mode.  The user can

* then interact with content while in this mode.  Such an application should

* provide an easy way for the user to toggle out of the mode (such as to

* check information in the status bar or access notifications).  In the

* implementation here, this is done simply by tapping on the content.

*

* {@sample development/samples/ApiDemos/src/com/example/android/apis/view/ContentBrowserActivity.java

*      content}

*

* <p>This second code sample shows a typical implementation of a View

* in a video playing application.  In this situation, while the video is

* playing the application would like to go into a complete full-screen mode,

* to use as much of the display as possible for the video.  When in this state

* the user can not interact with the application; the system intercepts

* touching on the screen to pop the UI out of full screen mode.  See

* {@link #fitSystemWindows(Rect)} for a sample layout that goes with this code.

*

* {@sample development/samples/ApiDemos/src/com/example/android/apis/view/VideoPlayerActivity.java

*      content}

*

* @param visibility  Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE},

* {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}, {@link #SYSTEM_UI_FLAG_FULLSCREEN},

* {@link #SYSTEM_UI_FLAG_LAYOUT_STABLE}, {@link #SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION},

* {@link #SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}, {@link #SYSTEM_UI_FLAG_IMMERSIVE},

* and {@link #SYSTEM_UI_FLAG_IMMERSIVE_STICKY}.

*/

从释义上可以知道,setSystemUiVisibility()是用于使系统UI进入一种临时的模式,目的是使用户的注意力关注于应用程序的内容上。所以单独一个Activity这样设置是可以全屏显示的,这个只对当前的Activity有效。可是当申请系统权限使,弹出的对话框是系统的Activity,通过adb shell mpsys activity 来看,当前最顶端的Activity已经是GrantPermissionsActivity。

Run #2: ActivityRecord{2b99111 u0 com.google.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity t141}

而这个GrantPermissionsActivity,我们并无法去设置它的setSystemUiVisibility()。所以这种方法不奏效。

通过和同事讨论,后来找到一种方法,可以实现我们的需求。

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

这种方法是OK的。

它的源码释义是:

/**

* Set the flags of the window, as per the

* {@link WindowManager.LayoutParams WindowManager.LayoutParams}

* flags.

*

* <p>Note that some flags must be set before the window decoration is

* created (by the first call to

* {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or

* {@link #getDecorView()}:

* {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and

* {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}.  These

* will be set for you based on the {@link android.R.attr#windowIsFloating}

* attribute.

*

* @param flags The new window flags (see WindowManager.LayoutParams).

* @param mask Which of the window flag bits to modify.

* @see #addFlags

* @see #clearFlags

*/

public void setFlags(int flags, int mask) {}

仔细分析发现,这个是设置整个当前Window的,而setSystemUiVisibility()聚焦于显示Activity内容的,还是有差别的。

/**

* Window flag: hide all screen decorations (such as the status bar) while

* this window is displayed.  This allows the window to use the entire

* display space for itself -- the status bar will be hidden when

* an app window with this flag set is on the top layer. A fullscreen window

* will ignore a value of {@link #SOFT_INPUT_ADJUST_RESIZE} for the window's

* {@link #softInputMode} field; the window will stay fullscreen

* and will not resize.

*

* <p>This flag can be controlled in your theme through the

* {@link android.R.attr#windowFullscreen} attribute; this attribute

* is automatically set for you in the standard fullscreen themes

* such as {@link android.R.style#Theme_NoTitleBar_Fullscreen},

* {@link android.R.style#Theme_Black_NoTitleBar_Fullscreen},

* {@link android.R.style#Theme_Light_NoTitleBar_Fullscreen},

* {@link android.R.style#Theme_Holo_NoActionBar_Fullscreen},

* {@link android.R.style#Theme_Holo_Light_NoActionBar_Fullscreen},

* {@link android.R.style#Theme_DeviceDefault_NoActionBar_Fullscreen}, and

* {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_Fullscreen}.</p>

*/

public static final int FLAG_FULLSCREEN      = 0x00000400;

从释义上得知,设置这个flag可以隐藏所有的屏幕修饰,像status bar,用于Window使用整个显示屏。这个完全是我们的目的了。

㈡ Android去除状态栏的方法汇总

一、隐藏标题栏

//隐藏标题栏

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

二、隐藏状态栏

//隐藏状态栏

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

三、去掉所有Activity界面的标题栏

修改AndroidManifest.xml

在application 标签中添加android:theme="@android:style/Theme.NoTitleBar"

四、去掉所有Activity界面的TitleBar 和StatusBar

修改AndroidManifest.xml

在application 标签中添加

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

安卓手机隐藏状态栏怎么操作

方法:

1、进入手机“设置”界面,依次点击“隐私权”→“恢复出厂设置”项

2、在弹出的“恢复出厂设置”窗口中点击“重置手机”按钮

3、接着点击“备份数据”按钮,对系统中的重要数据进行一次备份。

4、然后点击“消除全部数据”按钮。

5、此时手机会自动重启,并进行数据的清除操作。

6、重启完成后状态栏又出现。

㈣ Android 显示、隐藏状态栏和导航栏

Android 显示、隐藏状态栏和导航栏
控制状态栏显示,Activity的主题中配置全屏属性

控制状态栏显示,在setContentView之前设置全屏的flag

控制状态栏显示,在任何位置通过添加和移除全屏的flag

控制状态栏和导航栏显示,setSystemUiVisibility

// 全屏展示

// 非全屏显示,显示状态栏和导航栏

热点内容
手机号序列码的密码在哪里 发布:2025-02-02 03:29:34 浏览:873
安卓怎么换回鸿蒙系统 发布:2025-02-02 03:24:35 浏览:507
完美国际邻水镇箱子密码是多少 发布:2025-02-02 03:17:04 浏览:618
测试java程序 发布:2025-02-02 03:16:49 浏览:888
android罗升阳 发布:2025-02-02 03:15:01 浏览:822
javascript编程语言 发布:2025-02-02 03:05:49 浏览:360
用电账号初始密码多少 发布:2025-02-02 03:04:03 浏览:107
python赋值运算符 发布:2025-02-02 03:00:51 浏览:905
怎么查询电脑ip地址和dns服务器 发布:2025-02-02 02:57:50 浏览:240
数据库应用系统的概念 发布:2025-02-02 02:44:46 浏览:549