Hiding Title Bar / Notification Bar When Device Is Oriented To Landscape
Solution 1:
was searching for an answer, ended up here, put the pieces together and here they are:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
Solution 2:
Assuming you have defined configChanges
for the Activity
in the manifest then you can achieve your issue overriding onConfigurationChanged
method:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
getActionBar().hide();
} else {
getActionBar().show();
}
}
You will have to use getSupportActionBar()
instead of getActionBar()
if using the support library.
Solution 3:
first check your device orientation by using following code
The current configuration, as used to determine which resources to retrieve etc, as available from the Resources' Configuration object as:
getResources().getConfiguration().orientation
Then do the necessary coding related to hide title bar and notification bar.
Solution 4:
@Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
if(config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getActionBar().hide();
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getActionBar().show();
}
}
You can use this I have tried by my self.
Solution 5:
In your "AndroidManifest.xml", in the activity tag you can specify "NoTitleBar" in the theme property so that it will always hide the title:
<activityandroid:name="com.my_package.MyActivity"android:theme="@android:style/Theme.NoTitleBar.Fullscreen"android:configChanges="navigation|orientation|screenLayout|layoutDirection">
Post a Comment for "Hiding Title Bar / Notification Bar When Device Is Oriented To Landscape"