In my application manifest I've add android:configChanges to prevent activity reload/restart on rotate
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden|screenSize" >
it works, but supportActionBar ( I'm using AppCompat ) preserves his height with small font size.
ActionBar should be bigger in portrait and smaller in landscape, but it keeps the initial value:
- if I start in landscape, the actionbar stay thin in portrait
- if I start in portrait, the actionbar stay big in landscape
Removing android:configChanges="orientation|keyboardHidden|screenSize" is the only solution I've found, but the app restart on rotate, and I need to preserve application content
Starting in landscape and rotating screen to portrait (small action bar and small font height)
As others have pointed out you should save and restore the instance state instead of handling configuration changes yourself if possible. If you have good reason not to do that you can try to update the toolbar's height and text appearance after the configuration change.
The following code should work for the support library version of
Toolbar
. The attributesactionBarSize
,titleTextAppearance
andsubtitleTextAppearance
are provided by the support library.The code assumes that you have a custom attribute
appToolbarStyle
declared inattrs.xml
. If you don't need that you can adapt the code to useR.style.Widget_AppCompat_Toolbar
directly instead.If you want to keep
android:configChanges
, you can use this to force 56dp toolbar height, align icons and fix small text issue:Toolbar XML:
Styles XML:
By setting
android:configChanges="orientation|keyboardHidden|screenSize"
You declare that you will handle these config changes by yourself. In normal cases, you should not set that, and let Android recreate your Activity.
Edit:
If you want to keep the line
android:configChanges
, you have to overrideonConfigChanged()
and change everything needed by yourself, e.g. the size of the ActionBar/ToolBar.