Android 7.0 Dialog Unable to display the issue

Source: Internet
Author: User

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

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.