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 ();}