Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - ActionBar not resizing with onConfigurationChanged ( AppCompat )

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 portrait enter image description here

Starting in landscape enter image description here

Starting in landscape and rotating screen to portrait (small action bar and small font height) enter image description here

like image 730
Tiziano Munegato Avatar asked Sep 07 '15 08:09

Tiziano Munegato


1 Answers

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 override onConfigChanged() and change everything needed by yourself, e.g. the size of the ActionBar/ToolBar.

like image 114
Derek Fung Avatar answered Nov 18 '22 02:11

Derek Fung