in my activity I have multiple edit texts, and some animated sliders with buttons beneath them. The problem is when I open a slider and tap on the button, the screen "jumps" back up to the first edit text. How can I stop this from happening? I just want the screen to stay where it was after the button press. Any help will be appreciated.
EDIT/UPDATE I just played around with an iPhone. Would it rather be possible to remove focus from the edit text when the soft keyboard is minimized? (Removing the focus would work in regards to the original question of the screen navigating to the top by its self)
Add the following to your parent layout (i.e. LinearLayout, RelativeLayout, etc.)
android:focusableInTouchMode="true"
I used the following solution. I created a method:
public void clearFocusOnEditText(){
//editText.clearfocus()
}
I then added this method to my ontouch() and onClick() methods. I'm guessing this is not the best solution, but for all intents and purposes it works brilliantly.
add it in your manifest to the activity tag
android:windowSoftInputMode="stateHidden"
Related
I'm working on an Android app with Android Studio. I have a form with several field and 2 buttons at the bottom to either validate or going back. The problem is that as soon as I click in one of the EditText of the form, the 2 buttons are following the keyboard.
How to prevent these 2 buttons to show up and force them to stay at the bottom of the page, hidden behind the keyboard. The form is in a ScrollView, which is in a ConstraintLayout. I tried many things like having my 2 buttons in the ConstraintLayout. Also outside in a RelativeLayout with constraint at the bottom of the parent... I also tried to use LinearLayout instead of the ConstraintLayout and weight each component but the buttons are still there. The only way I found is to use a vertical LinearLayout without weighting the components. But then I have the problem of not seeing the buttons if the screen is too small. I would like buttons to stay at the bottom.
Is it normal? Do I have to fix it from the code by hiding the buttons when focusing on one of the TextEdit, or by the layouts?
The other thing is that if I click on the last field ("Ville"), the form doesn't move and I still see the first 2 lines...
Thanks a lot for your help
On your manifest.xml you can set android:windowSoftInputMode to adjustPan.
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustPan" />
From Android documentation:
Don't resize the window to make room for the soft input area; instead
pan the contents of the window as focus moves inside of it so that the
user can see what they are typing. This is generally less desireable
than panning because the user may need to close the input area to get
at and interact with parts of the window
Anyone help to add DONE button on top of soft keyboard like above screenshot shows.
Because I need Enter and Done both button on my Edit Text.
So, please suggest me If anyone have Idea.
Thanks in Advance...
How about just adding a custom Button in the bottom of your UI?
You can observe layout size changes -> find a case when keyboard appears and disappears (Remember its different case from screen rotation, different screen proportion)
Based on keyboard hidden/shown event you can show/hide your custom UI.
I guess only problem is, you don't know what is keyboard view background. But its definitely better than writting your own keyboard, AFAIK you can't add views to keyboards.
You have to create a custom keyboard for that. For custom keyboard you can try here:
https://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615
https://developer.android.com/guide/topics/text/creating-input-method.html
https://inducesmile.com/android/how-to-create-an-android-custom-keyboard-application/
http://www.blackcj.com/blog/2016/03/30/building-a-custom-android-keyboard/
You would like to have an easy solution? Then integrate your "Done" button in your layout. Your layout should look like this (short version):
<LinearLayout orientation="vertical">
<ScrollView layout_weight="1"> <-- if needed, use FrameLayout else
place your Layout here
</ScrollView>
<YourDoneButton/>
</LinearLayout>
Your Button will stack on the top of the keyboard. I assume, that the user should be able to click of the "Done" button even if the keyboard is hidden. If not, you can hide it if your EditText is not focused.
I have a little issue with the keyboard on my numberpicker.
It's kinda hard to explain in words so here are some screenshots:
When I click on the numberpicker the keyboard shows up:
When I click on the next button (in this case the 'Volg' button) I implemented that it should focus the next edittext.
But as you can see, the screen shifts a little to the top.
This is not a huge problem but it's kinda annoying.
What can cause this, or how can I fix this ?
Edit: the layout is a scrollview.
try this
In your manifest file under activity tag use attribute
android:windowSoftInputMode="stateUnchanged"
I have a layout which has one large EditText view at the top + a bunch of buttons at the bottom. The EditText is made to shrink and expand when the ime is activated/deactivated by using adjust_resize. The buttons at the bottom are pushed up above the ime.
I would like to hide these buttons when the ime displays, to provide enough space for the EditText view.
I have so far tried the following:
subclassed EditText and provided the activity the option to register a callback on the view's OnSizeChanged.
Used this callback to change the visibility of the buttons (actually the layout container) to GONE.
This work OK and does hide the buttons when the ime pops up.
However, the EditText does not expand into the new available space.
Furthermore, when the ime is disposed off, the EditText field is now bigger than it was originally, pushing (the now showing) buttons outside the screen.
I should also add that when typing the first letter into the view, and the ime displays the word options, the screen is redrawn and the EditText fills the vacant space.
Any ideas on how to get this to work?
Or even better, is there a simpler solution to my requirement?
Thanks...
NB: In my view, scrolling is not a good option.
I got this to work by changing the above method a bit:
Wrapped the entire layout with a FrameLayout
subclassed the FrameLayout and provided the activity the option to register a callback on the layout's OnMeasure
This gives the activity a chance to change visibility of views before these are measured.
I would still be very happy to hear about simpler solutions, especially in regards to figuring out whether the keyboard is currently visible or not.
(dumpsys window shows this information. Can we easily get to it?)
Have you tried to call myView.invalidade() ?
I was using the GONE property, but then changed to button.setVisibility(View.INVISIBLE); because I don't have any other stuff on my screen.
on the adjust_resize, you will need to check again when the keyboard has gone and show the buttons again.
In my android application, I have an EditText. When I click in this field, the soft keyboard appears, expanding from the bottom of the screen. It seems to actually modify my layout, pushing contents upwards. When I dismiss the keypad, it retracts, and I see my layout re-expand to take up the space it previously occupied.
Is there a way to get the keyboard to simply appear "on top" of my layout, so that I don't get this somewhat unpleasant relayout animation? The EditText is pinned to the very top of the screen, so I don't have to worry about the keypad hiding it.
Thanks
By default, Android should be using "Pan and Scan", which would work more or less how you described. The keyboard is displayed over your view, and you can scroll your view in the background. If you override the windowInputMode for you Activity, or Android determines that your Activity is resizable (because of the presence of a resizable field... ListView, ScrollViews, etc), it may resize your view instead, and it sounds like that's what you're running into. To force it to Pan and Scan try adding:
android:windowSoftInputMode="adjustPan"
as an attribute to the Activity element in your xml layout.
There's a third option as well. You can specify that when an EditText is selected it will be edited in full screen mode. The other controls in your view will be hidden, the user will be presented with just the keyboard, an EditText control, and optionally some other limited controls. If your EditText doesn't require a lot of context from other elements of your view, it may prevent a cleaner user interface. For more details, see: http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
Add:
android:windowSoftInputMode="adjustResize"
to your activity attr in manifest.xml. Hope it will help.
This questions seems to state a resize is not desirable. I had the same issue, but adding
android:windowSoftInputMode="adjustNothing"
to the manifest file instead solved my problem.