Practical code Segment 1: practical code segment

Source: Internet
Author: User

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.

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.