Activate a specific dimens.xml at runtime

2019-06-12 15:53发布

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?

2条回答
唯我独甜
2楼-- · 2019-06-12 16:17

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

android dynamically change style at runtime

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-06-12 16:39

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.

查看更多
登录 后发表回答