Trying to listen to orientation change in my android program, but nothing works. My solutions: Added android:configChanges="orientation"
to my activity in AndroidManifest and added this in my Activity class:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.d(TAG_ZT, "Config changed.");
navigation.setSelectedItemId(R.id.navigation_translator);
}
But it doesn't work.
Next my solution was adding:
OrientationEventListener orientationEventListener = new OrientationEventListener(MainActivity.this.getApplicationContext()) {
@Override
public void onOrientationChanged(int orientation) {
Log.d(TAG_ZT, "onOrientationChanged: "+orientation);
navigation.setSelectedItemId(R.id.navigation_translator);
}
};
But also No work. What I'm doing wrong?
You must be using API level 13 or higher. In this case use configChanges="orientation|screenSize"
otherwise onConfigurationChanged will not be called.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.