How to show Activity in Portrait or in Landscape mode.How to show Activity in Portrait or in Landscape mode.

Answer 1

For this we need to set the android:screenOrientation attribute in manifest.
To show the Screen/Activity in Landscape mode :
   


To show the Screen/Activity in Portrait mode :
   

Answer 2

In ONCREATE Method Configuration config = getResources().getConfiguration(); onConfigurationChanged(config); public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Checks the orientation of the screen if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){ Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show(); } }

SUBMIT YOUR ANSWER

  |  
 
 
 

Preview :