How do i fix android activity in a stable position? - android

I'm building a simple app for android that's taking input from the user via an EditText. But when the EditText is focused and the on screen keyboard appears it causes the whole layout to move a few dps so that the action bar slides under the statusbar. How can i fix the activity so that it doesn't move when the keyboard opens?
Tried this which made it better but it still moves a few dps
View dv=getWindow().getDecorView();
dv.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

Try using adjustResize as your activity's android:windowSoftInputMode. Add the following line in your manifest in that particular activity.
<activity android:windowSoftInputMode="adjustResize">
Also, check the other options available for windowsSoftInputMode.

Related

Control where the Android soft keyboard appears on the screen?

Is there a way to control where the soft keyboard appears on the screen? Assuming it takes the whole width, I would like to be able to specify a height so that the keyboard shows on the top half of the screen. Is this possible?
Currently I'm just showing the keyboard using SoftInputMode in the manifest file.
android:windowSoftInputMode="stateVisible"
Please try using android:windowSoftInputMode="stateAlwaysHidden" attribute and also apply this attribute in the previous activity of current activity in which the keyboard is opened.

Show Custom Toolbar while Scrolling Screen with Keyboard

Please read the question carefully before any action,
I am using the custom toolbar in my android application with one image, one button, and title.
Now below that, I have a full screen with edit texts and text views and buttons. While I am trying to fill data and keyboard is open at that time while I am scroll down my screen upside, it hides toolbar also, even toolbar is outside of scroll.
I have taken scrollbar inside the body view, not for the whole screen, but then also while I am scrolling it hides the toolbar.
Try this in manifest file it may work.
<activity
android:name=".YourActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" />
Use in your activity tag in Manifest file
<activity android:windowSoftInputMode="adjustResize"> </activity>
The activity's main window is always resized to make room for the soft keyboard on the screen.
Moreover, you can find the detail about it here official doc
Also, look at this question
Hope it will be helpful to you.

Do not resize UI layout elements when keyboard displayed

When the on-screen keyboard is displayed some UI elements in my layout shrink and/or disappear.
I do not want the underlying UI to change at all when the keyboard displays or hides.
Try try to prevent this I have added keyboardHidden to the configuration changes declaration in my Activity manifest believing that this would tell the system that I will handle any resizing required, but it has made no difference.
Is there a simple way to prevent any resizing when the keyboard displays and is hidden?
It sounds like you want the adjustPan option for the windowSoftInputMode attribute in the manifest:
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
The details of the different options can be found here
You add it to the activity definition in the manifest like this:
<activity
android:name=".ui.MyActivity"
android:label="#string/my_activity_title"
android:theme="#style/AppTheme"
android:windowSoftInputMode="adjustPan"/>
As above it's worth noting that using this will sometimes push part of your Activity off screen if there is a 'focused' element which would otherwise be hidden by the keyboard.

Android Facebook Messenger keyboard resize activity layout

I trying to fix layout resize in my Activity when keyboard appear on the screen. I've tried to put in manifest on the activity: windowsSoftInputMode="stateAlwaysHidden" but with not results, my layout is still resizing when I open the keyboard with someone on messenger which is unussual.
If you are doing what I think you are doing, stateAlwaysHidden is not the way to go about it.
<activity android:windowSoftInputMode="adjustPan" >
From the documentation
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing.
This is, I think what you want. The pan not to change
Here's a link to the documentation regarding it http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

Prevent background resize AND prevent auto-focus on activity start

After looking up various questions on stack overflow, I have found that many other people had the following problems:
Background gets resized when soft keyboard opens
Soft keyboard opens when activity starts
The solution to both of these lies in the ActivityManifest.xml.
To prevent the background image from being resized when the soft keyboard opens, you can add android:windowSoftInputMode="stateVisible|adjustPan" to the <activity> in the manifest.
To prevent the soft keyboard opening when the activity starts, you can add android:windowSoftInputMode="stateHidden" to the <activity> in the manifest.
The fact that one solution requires stateHidden and the other requires stateVisible means that I cannot use both solutions. I am looking to prevent the soft keyboard from stealing focus on activity start but also prevent the soft keyboard from resizing the background when the user does decide to focus on the EditText.
Is there a viable solution to both of these issues?
The fact that one solution requires stateHidden and the other requires
stateVisible means that I cannot use both solutions.
Yes. But, you can use stateHidden|adjustPan.
Keyboard will not pop up unless user clicks on an EditText. And potential changes to your background will be in terms of positioning; scaling of the background will not occur.
If your EditText is wrapped within a parent container, set android:focusableInTouchMode="true" for that container. Basically, make that container receive the initial focus when the activity starts. Take a look at this link
Is any part of your layout a scrollable container (like ListView)? If so, try setting android:isScrollContainer="false" on that item in your XML layout.
If you have any views which have android:isScrollContainer="true", the layout manager will attempt to resize your layout when the keyboard pops up, regardless of `android:windowSoftInputMode'.
Here's a similar question: What does android:isScrollContainer do?
There are basically two ways to fulfill your requirement.
Just use the below activity tag
android:windowSoftInputMode="adjustPan|stateAlwaysHidden"
Or
Using
android:windowSoftInputMode="stateVisible|adjustPan" to the activity tag in the manifest.
Now with your EditText use following android:focusableInTouchMode="true" with android:focusable="false".

Categories

Resources