I want to run a Hello World sample application only in landscape mode on my Device.
If the device changed to portrait, I would then like to raise one toaster. For example "please change to landscape mode to run your application".
How should I do this?
You can use the configChanges -attribute for the Activity you want to catch the screen-orientation change for. After that, the onConfigurationChanged() -method in your Activity will be called when the orientation changes.
What Does Landscape Mean? Landscape is a horizontal orientation mode used to display wide-screen content, such as a Web page, image, document or text. Landscape mode accommodates content that would otherwise be lost when viewed to the left or right. Portrait mode is landscape's counterpart.
Ensure that you have enabled Auto-rotate for your tablet. To do this, swipe down on the tablet to display the status bar and touch Auto Rotate.
You can go for both programmatically as follows:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
or also in manifest file you can give here as
<activity android:name=".YourActivity" android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"/>
add this to your activity tag in your manifest file:
android:screenOrientation="landscape"
It will fix your orientation to landscape mode and you need not to show any toast to user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With