I'm writing a custom EditText that will have functionalities to bold/italic/underline/lists .... for Android
It's working so far so good but I've a problem that when a user clicking on a Button (for styling bold/italic...), the user will lose focus on the EditText.
Anyone has any ideas how to prevent the button taking focus from the EditText?
Thanks :)
The easiest thing to do would be to have the onClickListener of those buttons refocus the edit text as their last instruction.
You can also try putting focusable=false (and focusableInTouchMode=false) on the buttons. That may work, I'm not sure if focus is removed from the edit text when the screen is touched or when another item receives focus, which is subtly but important difference here. It would also slightly change any drawables on the button that use focused state.
Related
Problem: In soft keyboard settings, there is a toolbar option, if we turn it on, it will give you some suggestions, for example, if a copied something, it will start appearing on the top of keyboard(marked red in the screen shot), if the user clicks that suggestion, it will be pasted on the edit text which have the focus.
Things i have tried.
override autofill method (not working, not called).
added text watcher, beforeTextChanged is called and the editable text is empty.
added the OnKeyListener (not working, not called).
added the onTextContextMenuItem (not working, not called).
Read bunch of questions on Stackoverflow but no question/answer is helping.
here is the screen shot:
PS: I am not sure how can i capture this click, and intercept the text, problem is that I am using the custom view for OTP, and when user click that suggestion, only first box is filled with the first character because we have max length equals to 1. I want to capture that text and fill it in my view accordingly. Any help is appreciated.
I have checked the following documents
https://developer.android.com/guide/topics/text/autofill
https://developer.android.com/guide/topics/text/copy-paste
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"
Is there a way to detect when the keyboard is about to be presented in Android?
My problem is that I have a ListView with EditTexts in it. When the keyboard is about to be presented, these are quite often redrawn, causing an EditText that was JUST tapped to lose focus and require an extra tap.
My proposed solution is to monitor when the keyboard is about to be shown, check to see which view currently has focus, then after the keyboard is done being shown, restore focus to that view.
However, I have no idea how to detect when the keyboard is "about to be shown" in Android. How would I do this?
(I would also accept an alternative answer that addresses my actual problem: EditText losing focus when keyboard is displayed)
You could do it the other way, create an unique OnFocusChangedListener myListener and set it to all your EditTexts and put a switch inside and store which is the last view getting/losing focus
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"
At first my EditText had the focus as soon as the app loaded the screen and I disabled that with
android:focusable="true"
android:focusableInTouchMode="true"
However, there is no way to lose focus after clicking the EditText. The focus is still there when I try to click outside of the text area. This also happens when I click on the EditText to change the value and press "Done" on the on screen keyboard. Does anyone know a way for me to accomplish this?
Focus only changes if you click on something else that can gain focus. Issue is: If you click on a button for instance you might not lose focus, unless you do what Mathew said. Problem with that is: A button whose focusableInTouchMode is set to "true", needs now to be clicked TWICE: Once for gaining focus and once for performing OnClick. A nagging issue, that was haunting me as well right now.