Activate a specific dimens.xml at runtime

时光怂恿深爱的人放手 提交于 2019-12-08 11:52:19

问题


I need to choose a specific dimens.xml at runtime after my app checks for screen capabilities. I DON'T WANT ANDROID CHOOSE IT FOR ME by selecting automatically by project folder (\values, \values-large, ...).

I have to do it manually due to the bad screen configuration (density and dimension) of my low-cost china tablet. Can I do that?


回答1:


Have you tried to force configuration change?

    DisplayMetrics metrics = new DisplayMetrics();
    metrics.densityDpi = DisplayMetrics.DENSITY_MEDIUM;
    metrics.setTo(metrics);

Not sure if it works though. It's generally a bad idea to ignore what the OS thinks is the best.




回答2:


Solved using styles/themes/... and activating a specific theme at runtime in onCreate() as described here:

android dynamically change style at runtime



来源:https://stackoverflow.com/questions/11312398/activate-a-specific-dimens-xml-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!