Android Disable status bar dropdown

Source: Internet
Author: User

 Public  class mainactivity extends appcompatactivity implements View . Onclicklistener {    PrivateObject Statusbarmanagerservice;PrivateMethod methoddisable;PrivateTextView Tvinfo;//Screenpinning_mode_flag = Statusbarmanager.disable_none//    | Statusbarmanager.disable_expand//    | Statusbarmanager.disable_notification_icons//    | Statusbarmanager.disable_notification_alerts//    // | Statusbarmanager.disable_clock//    // | Statusbarmanager.disable_system_info//    | Statusbarmanager.disable_home//    | Statusbarmanager.disable_search//    | Statusbarmanager.disable_back//    | statusbarmanager.disable_recent;    Private Final Static intScreenpinning_mode_flag =57081856;Private Final Static intNormal_mode_flag =0;Private Final Static intScreenpinning_mode_with_back_flag =52887552;Private Final Static intDate_settings_request =0;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);        Toolbar Toolbar = (Toolbar) Findviewbyid (;        Setsupportactionbar (toolbar);        Floatingactionbutton fab = (Floatingactionbutton) Findviewbyid (; Fab.setonclicklistener (NewView.onclicklistener () {@Override             Public void OnClick(View view) {Snackbar.make (view,"Replace with your own action", Snackbar.length_long). Setaction ("Action",NULL). Show ();        }        }); Tvinfo = (TextView) Findviewbyid (;//Get Android @hide class by reflection.        Try{//Reflection Get status bar managerClass Clsstatusbarmanager = Class.forName (""); Context AppContext = Getapplicationcontext ();if(AppContext! =NULL) {Statusbarmanagerservice = Appcontext.getsystemservice ("StatusBar"); Methoddisable = Clsstatusbarmanager.getmethod ("Disable",int. Class); }        }Catch(ClassNotFoundException e)        {Reflectionerror (e); }Catch(Nosuchmethodexception e)        {Reflectionerror (e); }    }Private void Reflectionerror(Exception ex)        {Tvinfo.setbackgroundcolor (; Tvinfo.settext ("Reflection Error:"+ ex.tostring ()); }Private void Disablestatusbar(intFlag) {Try{//implementation of the core.Methoddisable.invoke (Statusbarmanagerservice, flag); }Catch(Illegalaccessexception e)        {Reflectionerror (e); }Catch(InvocationTargetException e)        {Reflectionerror (e); }    }@Override     Public void OnClick(View v) {Switch(V.getid ()) { {disablestatusbar (Screenpinning_mode_flag); Break; } {disablestatusbar (Normal_mode_flag); Break; }        }    }@Override     Public Boolean Oncreateoptionsmenu(Menu menu) {//inflate the menu; This adds items to the action bar if it is present.Getmenuinflater (). Inflate (, menu);return true; }@Override     Public Boolean onoptionsitemselected(MenuItem Item) {//Handle Action Bar item clicks here. The Action Bar would        //automatically handle clicks on the Home/up button, so long        //As you specify a parent activity in Androidmanifest.xml.        intid = item.getitemid ();//noinspection simplifiableifstatement        if(id = = {//Enable Back button to return from SettingsDisablestatusbar (Screenpinning_mode_with_back_flag); Startactivityforresult (NewIntent (settings.action_date_settings), date_settings_request);return true; }return Super. onoptionsitemselected (item); }protected void Onactivityresult(intRequestcode,intResultCode, Intent data) {if(Requestcode = = date_settings_request) {//Disable Back button when returning from SettingsDisablestatusbar (Screenpinning_mode_flag); }    }}

Finally, you need to add the configuration file:xml

Android Disable status bar dropdown

Related Article

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: 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.