I’m working on a calculator, on landscape I’m adding more buttons so each button gets a bit smaller to fit the extra ones.
At this point I’m just using a small font size so they fit the smaller buttons in landscape mode, however I’d like to have bigger text on portrait than in landscale.
I’ve been trying to figure out a simple way to use different theme depending on screen orientation but I haven’t found an easy way to do it. Creating a different folder for landscape styles /values-land/style.xml doesn’t work since the theme is only applied when app is restarted.
How can I use different font sizes/themes depending on screen orientation?
I’d recommend using directories that define font size for both the portrait and landscape orientation. For example:
In each of the dimen.xml files, you would have the font size defined for your buttons.
When an activity is launched or the device is rotated, your xml layout will grab the font size appropriate for the current orientation.
Edit: In response to your use of
android:configChangesto capture the calculator display, I’d like to offer an alternative that should be easier to implement and simplify coding.In the example below, I am assuming your calc screen consists of a
TextViewnamedcalcDisplay.Using this code, the device will not only automatically restore the calculator display text on rotation, but since the activity is destroyed and recreated, the font size you want will be loaded as well.