Monitor status bar page hide and display, dynamic display and hide status bar via onwindowattributeschanged and Onsystemuivisibilitychange

Source: Internet
Author: User

Recently added system functions need to monitor the status bar hiding and display, a small study of the following combination of data to do the following summary:

First I use this windowattributeschanged method to listen to the video playback page status bar hide and display, by printing GetWindow (). GetAttributes (). Flags, gets the page properties to determine the display and hiding of the status bar, can be monitored normally!

  @Overridepublic void onwindowattributeschanged (Layoutparams params) {super.onwindowattributeschanged (params); LOG.E ("Even", "screen State" +getwindow (). GetAttributes (). Flags), if (GetWindow (). GetAttributes (). flags==8455424) {log.i (" TAG "," Full screen Status ");} else if (GetWindow (). GetAttributes (). flags==8454400) {log.i ("TAG", "non-full-screen state");}}
But soon found that other programs with this method of monitoring will only be performed once, after all, feel heterodoxy! So almost twists and turns successfully using the Onsystemuivisibilitychangelistener interface to monitor!

@Overridepublic void Onsystemuivisibilitychange (int visibility) {if (visibility==view.system_ui_flag_fullscreen| | Visibility==view.system_ui_flag_layout_fullscreen) {log.i ("TAG", "full-screen status ======");} ELSE{LOG.I ("TAG", "non-full-screen status ======");}}
Before due to Setonsystemuivisibilitychangelistener (this), listening, a few degrees to abandon this method and stalled! I'll take a walk.

The systemuivisibility (int visibility) method can pass in the arguments:     view.system_ui_flag_visible: Displays the status bar, activity does not display full screen (revert to the normal condition of the state).     view.invisible: Hides the status bar while the activity stretches the full-screen display.     the View.SYSTEM_UI_FLAG_FULLSCREEN:Activity is displayed in full screen and the status bar is hidden and overwritten.     View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN:Activity full screen, but the status bar will not be hidden, the status bar is still visible, the Activity Top Layout section will be obscured by the state.     view.system_ui_flag_layout_hide_navigation: Effect with View.system_ui_flag_layout_fullscreen     View.system_ui_layout_flags: Effect with View.system_ui_flag_layout_fullscreen     View.system_ui_flag_hide_ NAVIGATION: Hide virtual keys (navigation bar). Some phones use virtual keys instead of physical keys.     view.system_ui_flag_low_profile: The status bar displays in low-energy display state (low profile mode), and some icon displays on the status bar are hidden.

Write here simply put the status bar settings hidden and display methods are also organized:

The view class provides the setsystemuivisibility and Getsystemuivisibility methods that implement dynamic or hidden actions on the status bar, and get the current visibility of the status bar.

The following will validate the view's setsystemuivisibility (int visibility) method with a demo to implement the dynamic Operation status bar:

1, Maiactivity.class:

Package Com.example.handlestatusbar;import Android.annotation.suppresslint;import Android.app.activity;import Android.os.bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.View;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.relativelayout;import Android.widget.Toast, @SuppressLint ("Newapi") public class Mainactivity extends Activity implements onclicklistener{ Private Relativelayout mrlayout;private Button mBtn1, mBtn2, MBtn3, MBtn4, MBtn5, MBtn6, MBtn7, mBtn8; @Overrideprotected V OID onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); Mrlayout = (relativelayout) Findviewbyid (r.id.content); mBtn1 = (Button) Findviewbyid (R.ID.BTN1); mBtn2 = (Button) Findviewbyid (R.ID.BTN2); mBtn3 = (Button) Findviewbyid (R.ID.BTN3); mBtn4 = (Button) Findviewbyid (R.ID.BTN4); mBtn5 = ( button) Findviewbyid (r.id.btn5), mBtn6 = (button) Findviewbyid (r.id.btn6); mBtn7 = (Button) Findviewbyid (R.ID.BTN7); mBtN8 = (Button) Findviewbyid (R.ID.BTN8); Mbtn1.setonclicklistener (this); Mbtn2.setonclicklistener (this); Mbtn3.setonclicklistener (This), Mbtn4.setonclicklistener (This), Mbtn5.setonclicklistener (this); Mbtn6.setonclicklistener (This), Mbtn7.setonclicklistener (This), Mbtn8.setonclicklistener (this);} @Overridepublic void OnClick (View v) {//TODO auto-generated method Stubswitch (V.getid ()) {case r.id.btn1://show status bar, Activity does not display full screen (revert to stateful normal condition) mrlayout.setsystemuivisibility (view.system_ui_flag_visible); Break;case r.id.btn2:// Hides the status bar while activity stretches full screen mrlayout.setsystemuivisibility (view.invisible), break;case r.id.btn3://activity full screen, And the status bar is hidden and overwritten. Mrlayout.setsystemuivisibility (View.system_ui_flag_fullscreen), break;case r.id.btn4://activity full screen, but the status bar is not hidden from the overlay,        The status bar is still visible, and the Activity Top Layout section is obscured by the state mrlayout.setsystemuivisibility (View.system_ui_flag_layout_fullscreen); Case R.ID.BTN5://With mrlayout.setsystemuivisibility (View.system_ui_flag_layout_fullscreen); Mrlayout.setsystemuivisibility (View.system_ui_flag_layoUt_hide_navigation); break; Case R.ID.BTN6://With mrlayout.setsystemuivisibility (View.system_ui_flag_layout_fullscreen);        Mrlayout.setsystemuivisibility (View.system_ui_layout_flags);        Case R.ID.BTN7://Hide virtual keys (navigation bar) mrlayout.setsystemuivisibility (view.system_ui_flag_hide_navigation); Case R.ID.BTN8://The status bar displays in low-energy display state (low profile mode), and some icon displays on the status bar are hidden. Mrlayout.setsystemuivisibility (view.system_ui_flag_low_profile); break;}}}

2, Main.xml:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Tools:context =". Mainactivity "android:id=" @+id/content "> <linearlayout android:orientation=" vertical "android:lay        Out_width= "Match_parent" android:layout_height= "match_parent" > <button android:id= "@+id/btn1"         Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "@string/s1"/> <button android:id= "@+id/btn2" android:layout_width= "Fill_parent" android:layout_height= " Wrap_content "android:text=" @string/s2 "/> <button android:id=" @+id/btn3 "android:layout         _width= "Fill_parent" android:layout_height= "wrap_content" android:text= "@string/s3"/> <button Android:id= "@+id/btn4" AndroId:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "@string/s4"/> &lt ; Button android:id= "@+id/btn5" android:layout_width= "fill_parent" android:layout_height= "wrap_content "Android:text=" @string/s5 "/> <button android:id=" @+id/btn6 "android:layout_width=" fill _parent "android:layout_height=" wrap_content "android:text=" @string/s6 "/> <button Andro Id:id= "@+id/btn7" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:tex t= "@string/s7"/> <button android:id= "@+id/btn8" android:layout_width= "Fill_parent" Android oid:layout_height= "Wrap_content" android:text= "@string/s8"/> </LinearLayout> &LT;/RELATIVELAYOUT&G T
3, String.xml:

<?xml version= "1.0" encoding= "Utf-8"?><resources>    <string name= "App_name" >handlestatusbar </string>    <string name= "Hello_world" >hello world!</string>    <string name= "menu_ Settings ">Settings</string>    <string name=" S1 ">SYSTEM_UI_FLAG_VISIBLE</string>    < String name= "s2" >INVISIBLE</string>    <string name= "S3" >system_ui_flag_fullscreen</string >    <string name= "S4" >SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN</string>    <string name= "S5" > system_ui_flag_layout_hide_navigation</string>    <string name= "S6" >system_ui_layout_flags</ string>    <string name= "S7" >SYSTEM_UI_FLAG_HIDE_NAVIGATION</string>    <string name= "S8" >SYSTEM_UI_FLAG_LOW_PROFILE</string>  </resources>


Example is reproduced, I'd better knock it again!




Monitor status bar page hide and display, dynamic display and hide status bar via onwindowattributeschanged and Onsystemuivisibilitychange

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.