I need to change layout of my Android (4.1 API 16) application when orientation is changed.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main_2);
System.out.println("Orientation changed!");
}
Also I have added the next line to manifest file
android:configChanges="orientation"
I use Ctrl+F11 to change orientation. My screen rotates but layout stays the same and nothing is printed in LogCat. Feels like onConfigChanged event doesn’t occur.
Where is my mistake?
Thank you.
Try using
android:configChanges="orientation|keyboardHidden|screenSize"Source : Documentation
Hence, also add
"|screenSize" to configChangesif your application targets API 13 and above.