How to disable android keyboard in android application [duplicate] - java

This question already has answers here:
How to close/hide the Android soft keyboard programmatically?
(126 answers)
Closed 8 years ago.
I am creating a calculator app where i have an edittext where the result is shown.I want the data to be entered in the edit text only on clicking the number buttons NOT by the android keyboard.How do i disable the keyboard in my android app.Please help!

Try
editText.setInputType(EditorInfo.TYPE_NULL)
Or
((EditText) findViewById(R.id.LoginNameEditText)).setFocusable(false);
Or
editText.setKeyListener(null);

Try this :
InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

try below code:-
EditText ed = (EditText)findViewById(R.id.editText1);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(ed.getWindowToken(), 0);
ed.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(ed, InputMethodManager.SHOW_IMPLICIT);
}
});
or
Window.SetSoftInputMode (SoftInput.StateAlwaysHidden);

If other situations you can prevent the keyboard showing simply using in the manifest
android:configChanges="orientation|keyboardHidden"
In this way the Android keyboard will not auto-open but is shown only if you click directly the EditText

Just posting an Answer what #yahya already commented.
You should consider using a TextView which is not editable and hence won't make any calls to the Keyboard.
In onClick() event of your button's call the setText(String) method and the apply the text you wish. :)
Ypu can also easily append things as setText(yourTextView.getText().toString + "Your New Text");

Hi Kindly try this: For this you no need any Widgets Context...
InputMethodManager miInputManager = (InputMethodManager) Activity.this
.getSystemService(Context.INPUT_METHOD_SERVICE);
miInputManager.hideSoftInputFromWindow(Activity.this
.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);

Use
android:windowSoftInputMode="stateHidden"
for <activity> in Android_Manifest.xml

Related

Java how to get input for EditText from toggleSoftInput

I created EditText by drawing it on canvas so I have problem on making the keyboard appear when clicked and to make the EditText receive input. After some searching, I found out that I can use InputMethodManager to make the keyboard appear to give inputs for EditText.
Unfortunately, EditText does not receive any character inputs from anything pressed on the soft keyboard.
And I need to use imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); because when I used imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);the soft keyboard did not appear at all when EditText is pressed.
Code:
if((int)event.getX() > 50 && event.getX()<400 && event.getY() > 50 && event.getY() < 200){
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
How to solve this? Any working solution is welcomed. Thanks!
This should work fine.
EditText edit = (EditText) view.findViewById(R.id.passwordtextvalue);
edit.setOnKeyListener(this);
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
edit.requestFocus();
I have this in my app, and its working fine for edit text when I have the soft keyboard
Try this
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

android soft keyboard not showing on button click [duplicate]

This question already has answers here:
How to close/hide the Android soft keyboard programmatically?
(126 answers)
Closed 7 years ago.
Here is the method on buttonclick but it is not working... i have tried many things but nothing seems to be work
public void open_keyboard(View view)
{
message.msg_l(this, "keyboard clicked");
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
please try this,
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
Try something like this:
InputMethodManager imm = (InputMethodManager)getSystemService(MainActivity.this.INPUT_METHOD_SERVICE);
imm.showSoftInput(mainLayout.getWindowToken(), 0);

Closing keyboard after button click (breaks if no EditText is focused on) [duplicate]

This question already has answers here:
How to stop EditText from gaining focus when an activity starts in Android?
(54 answers)
Closed 8 months ago.
I put this on my button listener:
InputMethodManager inputManager =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);
It works perfectly for when the keyboard is up: it closes the keyboard and then continues its execution. The problem is that when no EditText was ever pressed (none of them are highlighted/focused on), it breaks and the app "stops working".
I guess it would be nice if I could check if an EditText had ever been pressed.
I tried to do this to check:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) // returns true if any view is currently active in the input method
{
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
EDIT
I ended up doing this:
I created this method:
public static void hideSoftKeyboard (Activity activity, View view)
{
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
}
I then called the method in my button listener like this:
hideSoftKeyboard(MainActivity.this, v); // MainActivity is the name of my class and v is the View I used in my button listener method.
Mediocre/bad solution, because it doesn't work as general as I want it to:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
EditText x = (EditText)findViewById(R.id.editText);
x.requestFocus(); // this way no matter what, an EditText is focused on.
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);

EditText focus can't set

When start run app,of EditText visibbility set "gone" value.After in java visibbility set value visible.
I want at that time open keyboard and focus to be on EditText.I do It ,but don't work
`
editText=(EditText)findViewById(R.id.search_text);
editText.setVisibility(View.VISIBLE);
editText.setFocusable(true);
editText.setSelectAllOnFocus(true);`
try to change it with:
editText.setFocusableInTouchMode(true);
editText.requestFocus();
Also this one:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

How to automatically show soft keyboard on start?

I have an activity that only has a EditText. I want the soft keyboard to show up automatically. How can I do this?
You can use this onResume:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(((EditText) findViewById(R.id.your_view)),InputMethodManager.SHOW_FORCED);
I suggest that you check if there is a Hardware keyboard before you force the keyboard to appear.
To hide:
((InputMethodManager) YourActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(findViewById(R.id.YOUR_VIEW).getWindowToken(), 0);
EDIT:
Try this:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

Categories