Activate keyboard on activity in background - android

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.

Related

How to always show soft keyboard and do not let it be closed?

I want to know 2 things
how to always show soft keyboard and do not let it be closed ( even when back or OK button was pressed ) ?
and how can I get an input from it?
I have already tried this code:
EditText yourEditText= (EditText) findViewById(R.id.ed);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
with these variants:
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
imm.toggleSoftInputFromWindow( yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
Use android:windowSoftInputMode="stateAlwaysVisible" in to AndroidManifest.xml file
Like this:
<activity android:name=".YourActivity"
android:label="#string/app_name"
android:windowSoftInputMode="stateAlwaysVisible" /> // OR stateVisible
If that activity having EditText so when ever Activity will start
your Keyboard automatically open
If you want to still open Keyboad after use done any operation then do this via programetically
InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInputFromWindow(
linearLayout.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
OR
To Show Soft Keyboard
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(EDITABLE_VIEW,
InputMethodManager.SHOW_IMPLICIT);
OR
EDITABLE_VIEW can be any view which has focus on screen like
mEditText = (EditText) findViewById(R.id.editText);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText ,
InputMethodManager.SHOW_IMPLICIT);
OR
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(editText.getWindowToken(), 0);
Documentation

Hide soft keyboard in android after using library

I cant hide soft keyboard from my code. I`m using some menthods:
in java code:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
in manifest:
android:windowSoftInputMode="stateHidden|adjustResize"
this dont work for me. Can you help me?
P.S: Its happend when I use this library https://github.com/Quinny898/PersistentSearch
Call this method from Activity where you want to hide soft keyboard (you can put it in to diffetent class & call using class name as its static)
public static void hideSoftKeyboard(Activity activity) {
InputMethodManager inputMethodManager = (InputMethodManager) activity
.getSystemService(Activity.INPUT_METHOD_SERVICE);
if (activity.getCurrentFocus() != null)
inputMethodManager.hideSoftInputFromWindow(activity
.getCurrentFocus().getWindowToken(), 0);
}

how to disable softkeyboard in an activity?

I want to disable keyboard pop up in my activity. There will not be any keboard in the actvity. but hardware keyboard must work.how to do this? hardware buttons must work
Just try below code.
InputMethodManager inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(editView.getWindowToken(), 0);
Use this in your manifest:
<activity android:name=".SampleActivity" android:windowSoftInputMode="stateAlwaysHidden"/>
Managing soft keyboard in android is not that easy, although you can hide keyboard programatically.
private void hideKeyboard() {
//This will get any view in focus.
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
note that Hardware Keyboard will work.

How to hide only soft keyboard 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);
}

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.

Categories

Resources