Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webview在第三方的Activity里,density适配无效。 #381

Open
Ian0903 opened this issue Oct 21, 2021 · 3 comments
Open

Webview在第三方的Activity里,density适配无效。 #381

Ian0903 opened this issue Oct 21, 2021 · 3 comments

Comments

@Ian0903
Copy link

Ian0903 commented Oct 21, 2021

重写 Activity 的 onCreateView(View parent, String name, Context context, AttributeSet attrs) 方法,在调用 super 之前调用一遍 AutoSize.autoConvertDensityOfGlobal(Activity)

Originally posted by @JessYanCoding in #5 (comment)

————————————————————————————————————————————

Webview在第三方的Activity里,继承的WebViewActivity设置的density失效了,重写了onCreateView方法重新设了一遍也无效。有好的办法吗?

@JessYanCoding
Copy link
Owner

#1 (comment)

@Ian0903
Copy link
Author

Ian0903 commented Oct 22, 2021

#1 (comment)

在启动WebviewActivity的时候按照如下方式替换了Context,但还是无效,发现重写的getResources方法没调用。

// 启动WebviewActivity

ARouter.getInstance()
      .build(WebRoutes.WEB_WEBVIEACTIVITY)
      .withString("url", url)
      .navigation(adjustAutoSize(context));

private static Context adjustAutoSize(Context context) {
        return new ContextWrapper(context) {
            private Resources mResources;

            {
                Resources oldResources = super.getResources();
                mResources = new Resources(oldResources.getAssets(), oldResources.getDisplayMetrics(), oldResources.getConfiguration());
            }

            @Override
            public Resources getResources() {
                AutoSizeCompat.autoConvertDensityBaseOnWidth(mResources, ALERT_BASE_WIDTH);
                return mResources;
            }
        };
    }

@JessYanCoding
Copy link
Owner

#13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants