a while back I converted my app to include landscape mode, from each activity having screenOrientation="portrait" to this:
<activity
android:name="bundle.android.views.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="fullSensor">
I also handle configuration changes just fine in onConfigurationChanged in each activity.
But in hindsight, I only want edge cases with pop out hardware keyboards to get landscape mode. How do I adjust my manifest and code?
do I keep a certain combination android:configChanges ? the onConfigurationChanged class? insight appreciated
One option is to tackle this problem programmatically. What you could do is detect if the user has a hardware keyboard attached, and if so force the orientation into landscape mode. Here are two ways to detect a hardware keyboard:
http://developer.android.com/reference/android/content/res/Configuration.html#keyboard
and
if (getResources().getConfiguration().hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
}
Once you have detected that the user has a hard keyboard you can force landscape mode on the user with:
myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Related
I have an activity with "portrait" orientation in AndroidManifest.xml.
When I start it from lock screen in landscape orientation, it appear with landscape for 1 second, and then change to portrait. The delay happens even if it's an blank activity (no view, no task).
Tell me how to avoid this delay. Remove transition effect, rotation effect? I know it could be device performance, but still want to fix this.
If you always wants to run your app in landscape mode than use this code in Manifest file for all activity
<activity
android:name=".yourAcitvity"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize"
/>
That't the default behavior of Android, you can verify this issue using system apps. For ex: open the Android's default messenger, and turn it to landscape and lock the phone, now unlock it and you can see the messenger has re aligned to portrait, that's because the home screen is set to portrait by default. In order to show the home screen the system aligns the device to portrait again.
Using the method shown in this thread - How to check visibility of software keyboard in Android?
I am able to detect keyboard hide when in portrait mode or in landscape mode where the keyboard is not in fullscreen. If keyboard in landscape mode is fullscreen then, the layout changes are not triggered and hence i cannot detect it in the OnGlobalLayoutListener !
Please help me with this? Is there no simple way to detect keyboard hide?
NOTE: I cannot afford to change anything in the manifest file. It should all be done through code dynamically!
Thanks!
I'm having a small user experience issue in my app;
When changing from landscape to portrait (or portrait to landscape) with the Soft Keyboard open, the keyboard hides.
What I want to do is to stop the keyboard hiding on orientation change.
(Edit - I don't want to force the keyboard open, if the keyboard was hidden before the orientation change, I want it to stay hidden - I want to retain the keyboards open/closed state).
I've looked around for an answer and it seems adding stateUnchanged to the windowSoftInputMode options in the manifest for the Activity is the correct way to solve this (as described in the android documentation:
android:windowSoftInputMode="stateUnchanged|adjustResize"
The problem is this seems to have absolutely no effect.
Does anybody know of any caveats to this functionality? Does it perhaps not work if the EditText which is focused is in a Fragment?
Add this to your code and it will work :
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
I am enabling orientation change in focusChangeListener of an edittext in my app.
It is working fine, but the issue is if the user flips the keyboard to landscape mode keyboard disappears.
It will come up only if user tap on edittext again or change orientation to portrait mode.
I need to display keyboard in landscape mode without touching the edittext.
Please help me.
Generally, its a bad idea to mess with the default IME behavior because there are devices out there with hardware keyboards.
Now, that you have been warned, listen for the orientation change and if the keyboard was visible before the change and there is no hardware keyboard on the device, show the keyboard manually.
Try using android:configChanges="orientation" into your manifest class.
<activity
android:name=".classname"
android:configChanges="keyboardHidden|orientation"
>
if works then accept it.
In my manifest file I specified android:configChanges="orientation". And I noticed that when turning off the screen while in landscape the onConfigurationChanged() method is called once with portrait status and then called again with landscape status when waking up the screen.
What is the reason for this ? Is there any way to disable it ?
Use this in your manifest file--
<android:configChanges="orientation|keyboardHidden" >
This will never let your screen change when you rotate the screen landscape or portrait.
Use this one in your android menifest
android:configChanges="orientation"
for landscap
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
if you want unspecified
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
The problem seems related to the lock screen which forces the layout back to portrait when switching screen off/on.
I solved my issue by ignoring calls to onConfigurationChanged() between the calls to onPause() and onResume()