I have managed to change the Orientation for my fragment in my activity.
The Orientation is changed when my device is rotated.
Now I want to same functionality when I click on a button in the fragment.
i.e. I want to change from portrait mode to LandScape mode when I click on a button on the portrait layout and visa vera.
I used
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
and
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
respectively.
But this made the auto rotate functionality stop working. How can I fix this issue?
When you need auto rotating use getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
Please try this
<activity
android:name="<class name with package>"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait">
Related
There is an android program
I have a bottom navigation bar inside my app that i don't want to change its orientation because of quality reduce
I want to rotate a fragment inside an activity when change orientation of the phone without activity rotation. how can i do this?
Thanks.
Open your Manifest.XML
Find your activity.
Add tag inside
<activity
android:configChanges="orientation"/>
I am using Listview
I'm playing video (on VideoView) on portrait mode (not on full screen) and when I change to
landscape mode the video stop.
When I change it to landscape that video will appear on full screen and will keep playing.
Any Suggestion?
You can add this in your manifest for that activity, and ensure the activity does not redraw the views.
<activity
android:name=".YourActivityName"
android:configChanges="orientation|screenSize">
</activity>
Please note that if you have handled the orientation changes for this activity separately, then adding this would skip that.
I have a listview with two buttons in my main.xml layout. On click of one button i'am creating a textview dynamically and adding it at the bottom of the screen to confirm the user interaction. When the user clicks 2nd button (Confirm button), i need to add that text to listview. To support landscape mode, i have the same layout file in layout-land folder. When i click on 1st button it is creating a textview with some text and adding at bottom of the screen. Now if a change the device orientation then it is loading the landscape main.xml and activity is recreating again. So my textview is getting collapsed. How can i prevent that the recreation of activity on orientation change. (But it should pick up the other layout file).
Just edit the Activity Tag in androidmanifest.xml.
<activity
android:configChanges="keyboardHidden|orientation"
android:name=".testActivity"
android:label="#string/app_name"></activity>
You should add screenSize
if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
Added in API level 13.
then it should be like this
<activity
android:configChanges="keyboardHidden|orientation|screenSize"
android:name=".testActivity"
android:label="#string/app_name"></activity>
http://developer.android.com/guide/topics/manifest/activity-element.html
I wish to disable the landscape view in an android application . I've used :
<activity android:name=".SomeActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
It works but there is a slightly big problem . If I rotate the screen the activity restarts , and when it comes back , the screen is still in portrait mode . I want my app to completely ignore the device's position . There is no point in disabling the landscape view if when I rotate the device the activity restarts ( the screen becomes black for a few seconds , and then the activity appears again still in portrait mode ) .
android:configChanges="orientation|keyboardHidden|keyboard"
write a class and extend it to the activity. In that class add this code to a method.
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Then call this method to the activites to which you want to disable the landscape mode..
I specified an activity to be portrait-only in menifest file:
<activity android:name="mytest"
android:alwaysRetainTaskState="true"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
android:screenOrientation="portrait">
But it won't work on Droid when its hard keyboard is popped out.
When hard keyboard is popped out, the device always renders the layout of the activity in landscape orientation first, then it switches it back to portrait orientation. How can I let the app only render the activity in portrait orientation?
Can anyone help? Thanks.
Try using this in your activity description
android:configChanges="keyboardHidden"