Android full screen (includes three methods to hide the top status bar and title bar, and one method to hide the bottom status bar of the android 4.0 tablet)

Source: Internet
Author: User

Method 1

Public class mainactivity extends activity {@ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); // hide the title bar requestwindowfeature (window. feature_no_title); // hide the status bar getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen, windowmanager. layoutparams. flag_fullscreen); setcontentview (R. layout. activity_main );}}

Method 2

<! -- Hide the status bar and title bar at the same time --> <activity Android: Name = "com. ysj. demo. mainactivity "Android: theme =" @ Android: style/theme. notitlebar. fullscreen "Android: Label =" @ string/app_name "> <intent-filter> <action Android: Name =" android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity>

Method 3

<! -- Application theme. --> <style name = "apptheme" parent = "appbasetheme"> <! -- All mizmizations that are not specific to a special API-level can go here. --> <! -- Hide the status bar --> <item name = "Android: windowfullscreen"> true </item> <! -- Hide the title bar --> <item name = "Android: windownotitle"> true </item> </style>

Note:

1. The two sections of code in method 1 should be before setcontentview.

2. method 2 can only hide the status bar and title bar at the same time.

3. method 1 and method 2 are only applied to a single activity. Method 3 is applied to the entire program.

For tablets running Android 4.0 or above, the following three methods do not hide the status bar below the screen.

Public class startupactivity extends activity {@ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_startup);/** hide the status bar */try {string procid = "79"; if (Android. OS. build. version. sdk_int> = android. OS. build. version_codes.ice_cream_sandwich) procid = "42"; // ICS // requires the root permission process proc = runtime.getruntime(cmd.exe C (New String [] {"Su", "-c ", "service call activity" + procid + "S16 COM. android. systemui "}); // was proc. waitfor ();} catch (exception ex) {toast. maketext (getapplicationcontext (), Ex. getmessage (), toast. length_long ). show () ;}@ overrideprotected void ondestroy () {// todo auto-generated method stub/** resume the status bar */try {process proc = runtime.getruntime(cmd.exe C (New String [] {"am ", "startservice", "-n", "com. android. systemui /. systemuiservice "}); Proc. waitfor ();} catch (exception e) {e. printstacktrace ();} super. ondestroy () ;}@ overridepublic Boolean oncreateoptionsmenu (menu) {// inflate the menu; this adds items to the action bar if it is present. getmenuinflater (). inflate (R. menu. startup, menu); Return true ;}@ overridepublic Boolean onoptionsitemselected (menuitem item) {// todo auto-generated method stubswitch (item. getitemid () {case R. id. action_exit: Finish (); break;} return true ;}}

Because there is no status bar, you must provide the exit method in the program.

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.