Practical code Segment 1: practical code segment
1,
/*** Hide the status bar ** @ param context * Context object * @ return successfully collapse the status bar and return true; otherwise, false */public static boolean collapseStatusBar (context) is returned) {Object statusbarService = context. getSystemService ("statusbar"); if (statusbarService = null) {return false;} try {Class <?> StatusBarManager = Class. forName ("android. app. statusBarManager "); if (statusBarManager = null) {return false;} Method collapseMethod; if (Build. VERSION. SDK_INT> = Build. VERSION_CODES.JELLY_BEAN_MR1) {collapseMethod = statusBarManager. getMethod ("collapsePanels");} else {collapseMethod = statusBarManager. getMethod ("collapse");} if (collapseMethod = null) {return false;} collapseMethod. invoke (statusbarService);} catch (Exception e) {e. printStackTrace (); return false;} return true ;}
2,
/***** Expand the status bar ** @ param context * Context object * @ return returns true if the status bar is successfully expanded; otherwise, false */public static boolean expandStatusBar (context) is returned) {Object statusbarService = context. getSystemService ("statusbar"); if (statusbarService = null) {return false;} try {Class <?> StatusBarManager = Class. forName ("android. app. statusBarManager "); if (statusBarManager = null) {return false;} Method expandMethod; if (Build. VERSION. SDK_INT> = Build. VERSION_CODES.JELLY_BEAN_MR1) {expandMethod = statusBarManager. getMethod ("expandNotificationsPanel");} else {expandMethod = statusBarManager. getMethod ("expand");} if (expandMethod = null) {return false;} expandMethod. invoke (statusbarService);} catch (Exception e) {e. printStackTrace (); return false;} return true ;}
3,
/*** Get the status bar height ** @ param context * Context object * @ return Status Bar Height */public static int getStatusBarHeight (context) {Class <?> C = null; Object obj = null; Field field = null; int x = 0, statusBarHeight = 0; try {c = Class. forName ("com. android. internal. r$ dimen "); obj = c. newInstance (); field = c. getField ("status_bar_height"); x = Integer. parseInt (field. get (obj ). toString (); statusBarHeight = context. getResources (). getDimensionPixelSize (x);} catch (Exception e) {e. printStackTrace ();} return statusBarHeight ;}
4,
/*** Switch to full screen ** @ param activity * activity instance */public static void switchToFullScreen (Activity activity) {activity. getWindow (). clearFlags (WindowManager. layoutParams. FLAG_FORCE_NOT_FULLSCREEN); activity. getWindow (). addFlags (WindowManager. layoutParams. FLAG_FULLSCREEN );}
5,
/*** Switch to a non-full screen ** @ param activity * activity instance */public static void switchToNoFullScreen (Activity activity) {activity. getWindow (). clearFlags (WindowManager. layoutParams. FLAG_FULLSCREEN); activity. getWindow (). addFlags (WindowManager. layoutParams. FLAG_FORCE_NOT_FULLSCREEN );}
6,
/*** Enable the touch position display function ** @ param context * Context object */public static void showTouchLocation (context) {android. provider. settings. system. putInt (context. getContentResolver (), "show_touches", 1 );}
7,
/*** Disable the touch position display function ** @ param context * Context object */public static void hideTouchLocation (context) {android. provider. settings. system. putInt (context. getContentResolver (), "show_touches", 0 );}
Note: Some prototype codes are from the network.