Common android development methods

Source: Internet
Author: User
1. // obtain the number of workers corresponding to each 1mm on the screen. This method is sometimes inaccurate and requires the standard DPI value private int getpxofmm (context) of the mobile phone) {// 1 inch = 25.4mm float mmcount = 25.4f; displaymetrics dm = context. getresources (). getdisplaymetrics (); // obtain the number of dimensions on the diagonal line. Double diaonalpixels = math. SQRT (math. pow (DM. widthpixels, 2) + math. pow (DM. heightpixels, 2); // obtain the diagonal length (MM) Double diagonallength = diaonalpixels/DM. densitydpi * mmcount; // obtain the number of workers corresponding to each millimeter. Int result = (INT) math. ceil (diaonalpixels/diagonallength); return result;} 2. Get the android resolution displaymetrics dm = new displaymetrics (); windowmanager WM = (windowmanager) This. mcontext. getsystemservice (context. window_service); WM. getdefadisplay display (). getmetrics (DM); 3. In androidmainfest. select the activity in XML and set the windowsoftinputmode attribute to adjustunspecified | statehidden For example: <activity Android: Name = ". main "Android: Label =" @ string/app_name "Android: windowsoftinputmode =" adjustunspecified | statehidden "Android: configchanges =" orientation | keyboardhidden "> <intent-filter> <action Android: name = "android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity>

4. 3. Set the alertdialog button to not disappear

Try {field = dialog. getclass (). getsuperclass (). getdeclaredfield ("mshowing"); field. setaccessible (true); field. set (dialog, true); // true: disappears after clicking, and false: does not disappear after clicking} catch (securityexception e) {e. printstacktrace ();} catch (nosuchfieldexception e) {e. printstacktrace ();} catch (illegalargumentexception e) {e. printstacktrace ();} catch (illegalaccessexception e) {e. printstacktrace ();}

 

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.