How to hide only soft keyboard android - android

In my application i am using tab activity and activity group. In one of the activity i have edit texts. When the user click on the edit text, soft keyboard appears. But when the user click on the back button the soft key board dismisses and the previous activity on the activity stack appears.
Earlier on other application when i press back button when there is soft keyboard on the screen, only soft keyboard dismiss and it wouldn't go back to previous activity unless i press the back button again. I want this to happen in my current application as well. Plz Help.

Use below in your On create Method. it is working fine.
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

can try this-
**
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
**

InputMethodManager imm = (InputMethodManager)
this.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isAcceptingText()) {
System.out.println("Software Keyboard was shown");
} else {
System.out.println("Software Keyboard is hidden");
}
This does the trick. I checked if the soft key board is opened it stays at the current activity, otherwise it goes to previous activity.

code
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
check below link also :-
http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange
http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html

I think this will help you
protected void hideSoftKeyboard(EditText input) {
input.setInputType(0);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
}

Related

Not able to hide keyboard while using Search Widget

I am using Search Widget to implement search interface in my app in action bar. As soon as the activity starts the keyboard pops up even if I have not interacted with the search widget. So for that I added the attribute in the activity tag in manifest file windowSoftInputMode giving value either stateHidden or stateAlwaysHidden but this did not worked. So I tried to do it programmatically using the hideSoftInputFromWindow method but this also did not worked.
What does this causes to pop up the keyboard even after the attributes are set not to show and how to solve this issue? Please help!
Try to Use this functions to show OR hide the keyboard:
/**
* Hides the soft keyboard
*/
public void hideSoftKeyboard() {
if(getCurrentFocus()!=null) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
0);
}
}
/**
* Shows the soft keyboard
*/
public void showSoftKeyboard(View view) {
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(INPUT_METHOD_SERVICE);
view.requestFocus();
inputMethodManager.showSoftInput(view, 0);
}
Just set focus as false at first time when that screen loaded. By default when screen loaded, the focus goes to first edittext and Keyboard appears.set like this
view.setFocusable(false);
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
and on clickListener of that view make that view as focused. by using
view.requestFocus();
You can try to set the focus on any other view of the activity like this:
view.requestFocus();
I spotted the problem and solved the issue. I was using android.widget.SearchView and changed it to android.support.v7.widget.SearchView, after which I didn't even need to use windowSoftInputMode in the manifest or the hideSoftInputFromWindow() method. Please note!

Activate keyboard on activity in background

I implemented an invisible click through activity in my application with setting the theme as:
android:theme="#android:style/Theme.Translucent.NoTitleBar"
And adding falgs as follows before super.onCreate() in my invisible activity
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
Now i can interact with the previous activity but the keyboard does not appear when needed (eg. login forms). Is there any possible solution to activate the keyboard while keeping the invisible activity running?
Try this to show the keyboard
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(field, InputMethodManager.SHOW_FORCED);
And this to hide
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
You can perform it onResume() of your Activity.

Controlling the Soft Keyboard during onClick - Android

I had an issue where if user was typing and hit submit, the keyboard would not go away, so I found this code to fix that issue (by placing this in the onClick method):
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
However, if the user manually closed the keyboard, then clicked submit, I found the code above would bring the keyboard back -- not good.
The question:
Is there better code to use? OR can I just say something like =
if (keyboard = displayed) {
// do code above
} else {
// do nothing
}
To hide the keyboard:
final InputMethodManager inputMethodManager =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
To show it:
final InputMethodManager inputMethodManager =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_FORCED);

How to display the soft keyboard only on the click event of edittext in android?

My android Activity has an EditText. Whenever the screen loads the soft keyboard automatically pops up. This obscures the visibility of my screen. I want to display the soft keyboard only on the click event of that EditText.
How can I do this?
In my code I got something like this:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(password.getWindowToken(), 0);
imm.hideSoftInputFromWindow(username.getWindowToken(), 0);
where password and username are TextEdit views.
And to show:
imm.showSoftInputFromWindow(username.getWindowToken(), 0);
Try with this..
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
To Close u can use
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
This is how to show and/or how to close it.
So when you start the activity, use first the close code.

Forcing the default Android soft-keyboard to show

I have an activity (forced into protrait mode) that is required to show the default soft-keyboard. So I thought I'd set focus to the edittext when the activity is launched... so far so good.
Two issues
the soft-keyboard shall not be
dismiss-able for this activity
the soft-keyboard needs to be
elevated 50 pixels from the bottom
of the screen
Looking for assistance to solve these two issues. thanks.
to solve #1
private void hideSoftKeyboard()
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mAutoCompleteTextView.getApplicationWindowToken(), 0);
}
private void showSoftKeyboard()
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
}
#2 has no solution

Categories

Resources