资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

android隐藏状态,android控件隐藏和显示

Android 完全隐藏状态栏方法

Android 完全隐藏状态栏方法  

乌海海南网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、自适应网站建设等网站项目制作,到程序开发,运营维护。成都创新互联公司2013年至今到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司

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.

*

* pThis 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.

*

* pTwo representative examples of the use of system UI visibility is

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

* and a video playing application.

*

* pThe 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}

*

* pThis 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 dumpsys 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.

*

* pNote 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.

*

* pThis 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使用整个显示屏。这个完全是我们的目的了。

安卓11小窗模式下隐藏状态栏

单击右键就可以了。

首先你在任务栏上单击右键把锁定状态栏前面的对号去掉,再用鼠标放在状态栏上当鼠标变成上下箭头时,把状态栏拖到最下面。这样就看不到状态栏了。

状态栏是包含文本输出窗格或“指示器”的控制条。输出窗格通常用作消息行和状态指示器。消息行示例包括命令帮助消息行,它简要解释了“MFC应用程序向导”所创建的默认状态栏的最左边窗格中选定的菜单或工具栏命令。

Android 隐藏状态栏、标题栏、透明状态栏的几种方式

不管是继承AppCompatActivity还是Activity都适用:

在style.xml定义

在AndroidManifest.xml里面设置下theme属性:

1.在style.xml定义

2.在AndroidManifest.xml里面设置下theme属性

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

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

控制状态栏显示,Activity的主题中配置全屏属性

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

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

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

// 全屏展示

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

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"


本文标题:android隐藏状态,android控件隐藏和显示
URL网址:http://cdkjz.cn/article/phcepd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220