Dialog does not display when the app is logged on on Android 7.0, but the translucent background displays
After searching and comparing, it was found that the problem was caused by rewriting the getresources () method.
1 /**2 * Settings app does not change with system font adjustment3 */4 @Override5 PublicResources getresources () {6Resources Resources =Super. Getresources ();7Configuration Configuration =resources.getconfiguration ();8 configuration.settodefaults ();9 resources.updateconfiguration (Configuration, Resources.getdisplaymetrics ());Ten returnresources; One}
Configuration.settodefault () method
1 /**2 * Set This object to the system defaults.3 */4 Public voidsettodefaults () {5Fontscale = 1;6MCC = MNC = 0;7Locale =NULL;8Usersetlocale =false;9Touchscreen =touchscreen_undefined;TenKeyboard =keyboard_undefined; OneKeyboardhidden =keyboardhidden_undefined; AHardkeyboardhidden =hardkeyboardhidden_undefined; -Navigation =navigation_undefined; -Navigationhidden =navigationhidden_undefined; theOrientation =orientation_undefined; -Screenlayout =screenlayout_undefined; -Uimode =ui_mode_type_undefined; -SCREENWIDTHDP = COMPATSCREENWIDTHDP =screen_width_dp_undefined; +SCREENHEIGHTDP = COMPATSCREENHEIGHTDP =screen_height_dp_undefined; -SMALLESTSCREENWIDTHDP = COMPATSMALLESTSCREENWIDTHDP =smallest_screen_width_dp_undefined; +DENSITYDPI =density_dpi_undefined; ASeq = 0; at}
The Phonewindow code on Android 7.0 has changed, Decorview a class from Phonewindow, and calls the Updateavailablewidth () method at initialization time
1 private void updateavailablewidth () {2 Resources res = getresources (); 3 mavailablewidth = res.getconfiguration (). SCREENWIDTHDP, Res.getdisplaymetrics ()); 5 }
The Getresources () method is called, but the method is set to Settodefault (), and the SCREENWIDTHDP obtained is the default value screen_width_dp_undefined
1 /** 2 * Default value for {@link #screenWidthDp} indicating that no width3 * has been specified. 4 */ 5 Public Static Final int screen_width_dp_undefined = 0;
The default value in the code is 0, so the Mavaliablewidth value is 0, which causes the problem that Dialog cannot display.
Workaround:
Only the Fontscale in the GetResource () method is set to 1, and the other values are not modified.
1 /**2 * Settings app does not change with system font adjustment3 */4 @Override5 PublicResources getresources () {6Resources Resources =Super. Getresources ();7Configuration Configuration =resources.getconfiguration ();8Configuration.fontscale = 1;9 resources.updateconfiguration (Configuration, Resources.getdisplaymetrics ());Ten returnresources; One}
Reference: HTTP://WWW.JIANSHU.COM/P/9BE83BE8D1EF
Android 7.0 Dialog Unable to display the issue