I have a screen with edittext and one button.
Edittext has properties
android:focusable="true"
android:focusedByDefault="true"
android:focusableInTouchMode="true"
Button has the same properties with false values.
On pressing the button there is a change edittext gravity. The edittext does not lose focus when button clicked. But keyboard is hidding.
How to make the keyboard not to hide and stay visible in this case?
You can do this programatically. Call this when you click Button.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
or
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
You can do this also with a tag like so:
button.setTag(R.id.DONT_HIDE_KEYBOARD, "true");
and under values/ids.xml, add:
<item name="DONT_HIDE_KEYBOARD" type="id"/>
try following.code,here focus is your EditText.
fun closeInput(focus: View?) {
val inputMethodManager = mActivity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(focus?.windowToken, InputMethodManager.HIDE_NOT_ALWAYS)
}
I have a cordova android app.
I'm trying to prevent native android keyboard to show when user clicks on html input, or input gets focus programmatically.
It there for android something like:
keyboard.addEventListener('will-show',
functon(event){
event.disableKeyboardShow();
});
Thanks in advance!
I don't know if there is an event like you pointed. But you can prevent keyboard to showup automatically by doing this:
1) Insert on your onCreate():
InputMethodManager imm = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
View view = this.getCurrentFocus();
if (view == null) {
view = new View(this);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
2) Then you assure your EditText can get focus when needed by adding android:focusable="true" and android:focusableInTouchMode="true" elements in the parent layout of EditText like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout" android:focusable="true" android:focusableInTouchMode="true">
If you don't want your EditText to get focus anyway, put false at elements on step 2 and insert another one: android:descendantFocusability="blocksDescendants"
I have a layout which contains a ListView and a EditText below the ListView which is used for searching in list view. The problem is that when i close the soft keyboard after a search, it gives a jerk and shows white space while closing the soft keyboard. I have tried adjustPan, but it moves the whole layout up.
public static void hideKeyboard(Context context,View v)
{
InputMethodManager imm = (InputMethodManager)context.getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
Hope this helps!
I have a textview.On clicking the texstview the edit text comes up with focus. But to get the numpad another click is required.
I want that when i click on TextView,the edit text should come up with the numpad togeter withoutanother click on the editText.Not through xml.But manually
In the xml i have already given it as android:inputType="number"
(the text view is made invisible on click)
The on click method----
case R.id.txtPhoneNo:
hintPhoneNum.setVisibility(View.VISIBLE);
phoneNum.setVisibility(View.GONE);
edtPhoneNum.setVisibility(View.VISIBLE);
edtPhoneNum.requestFocus();
edtPhoneNum.setText("");
WHen the editText gets focus how to get the numpad forcefully?
The correct answer is
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);
for your EditText add the following XML:
android:inputType="number"
EDIT
Try requesting focus just after your textView was set invisible:
yourTextView.setVisibility(View.INVISIBLE); //or View.GONE
yourEditText.requestFocus();
This should display the keypad immediately
when TextView is shown or touched first it gets focus and when you click on it again it performs onClick() so you have to handle Foucus of TextView to achieve what you want.
A lot of time was spent to solve the problem, and it looks easy, but I'm really tired and couldn't find the solution.
I have an Activity, activity has 4 EditText components, 2 of them has popup menu (AlertDialog) which contain the list, next one - is disabled for edit, and last one - is editable, and should show the soft keyboard, when user is tapping on it.
Also, my root LinearLayout has LinearLayout which contain inside RelativeLayout. The last one is need for AdvBanner. Last LinearLayout(RelativeLayout) is aligned to the bottom of root layout.
The part of XML that describes it:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="bottom">
<RelativeLayout
android:id="#+id/AdvLayoutReserveArea"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#FFFFFF"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="bottom" />
</LinearLayout>
When activity is start, editable EditText has focus with GREEN border and cursor is blinking. After few seconds left, the AdvBanner is loaded and shown. When it happens, editable EditText lost focus.. from this moment, my life be like a nightmare.
Let's look step by step.
Problem 1.
If in THIS MOMENT (when Adv loaded and appears) user is editing an EditText field via the soft keyboard, focus is lost, border take a GRAY color, and if user continue to typing a text is have no result - symbols are not printed (CURSOR in EditText is too lost).
I THINK any user will be annoyed - when you typing text, and cursor is inactive, because in background some adv is loaded and it take focus for self.
To solve this, in method when Adv is loaded (is shown) I try to back focus manually to EditText by requestFocus method.
public void onAdLoaded()
{
// TODO Auto-generated method stub
// add app specific code for this event here...
// called when an ad is successfully displayed on device
CountEdit1.requestFocus();
}
Yes, the cursor is returned to EditText field, and if soft keyboard is active, user can still typing text, but border of EditText field stay GRAY...
NOTE: actually I'm not sure about the difference between GREEN and GRAY border of focused EditText.. GREEN is usually when user is tapping on it, and GRAY, probably, when we want to request a focus manually (using requestFocus() etc)
Problem 2. (As result of solvation Problem #1).
After soft keyboard was closed, if user tap on editable EditText field, it take focus and cursor appears inside, but no reaction for showing soft keyboard again! Tapping of it do not show soft keyboard, but looks like the edit field in copy mode - when user can select a text and cut/copy it to clipboard.
My goal is easy for a first look. I just want to SAVE the cursor and focus to editable EditText field (CountEdit1) while soft keyboard is shown and user typing some text.
And normal reaction when user tapping EditText - as usually, just show me the soft keyboard!
I read all issues here, I combined different methods (clearFocus, requestFocusFromTouch etc), just not enough of time and space to describe all that I tried to do to solve this. The main problems are described above.
Hope for help and solving the problem...
Thanks in advance..
The goal is solved, the workaround is an easier than I thought. Problem #2 is fixed by using onClick () method. Sufficient condition for appearing of soft keyboard that use of both clearFocus() and requestFocus() methods.
CountEdit1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
CountEdit1.clearFocus();
CountEdit1.requestFocus();
}
});
The soft keyboard appears when user is tapping on the EditText field.
Fixed.
Works for me:
InputMethodManager mgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
editField.requestFocus();
mgr.showSoftInput(editField, InputMethodManager.SHOW_IMPLICIT);
userInput.post(new Runnable() {
public void run() {
userIdInput.requestFocus();
}
});
Have a go at this and tell if your problem is still unsolved.
You should request focus after view is created in fragment or activity:
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
CountEdit1.requestFocus();
}
try this:
public void onAdLoaded()
{
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
CountEdit1.requestFocus();
InputMethodManager mgr = (InputMethodManager) base.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(CountEdit1, InputMethodManager.SHOW_IMPLICIT);
CountEdit1.setSelection(CountEdit1.getText().length());
}
},0);
}