问题
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