I am designing an android app that is primarily used with an external keyboard. There are a few edit texts that I dynamically set the focus on. The problem is that whenever the focus is set, the soft input keyboard pops up. I would like to know how to disable this. But, if a user presses a button, I want to display a popup box along with enabling the keyboard. Can this be done? Can you completely disable the popup keyboard, and then enable it if a user presses a button to open a popup menu? Any help would be greatly appreciated.
Asked
Active
Viewed 566 times
0
-
1sooo.. you want to disable the keyboard until someone presses the keyboard???? – T McKeown Jul 28 '14 at 17:39
-
I want the soft keyboard to be disabled from edit texts unless a button is pressed. – user3781214 Jul 28 '14 at 17:45
-
Check these answers http://stackoverflow.com/questions/10611833/how-to-disable-keypad-popup-when-on-edittext – user3885173 Jul 28 '14 at 17:45
1 Answers
0
Use this:
public class MyActivity extends Activity
{
private EditText ed;
private Button b;
private InputMethodManager imm;
private boolean hide = true;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ed = (EditText) findViewById(R.id.edit);
b = (Button) findViewById(R.id.button);
imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
b.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if(hide)
{
hide = false;
imm.hideSoftInputFromWindow(ed.getWindowToken(), 0);
}
else
{
hide = true;
imm.showSoftInput(ed, 0);
}
}
});
}
}
and in the manifest in the activity tag:
<activity
android:windowSoftInputMode="stateAlwaysHidden"

Goran Horia Mihail
- 3,536
- 2
- 29
- 40
-
I have tried the stateAlwaysHidden, but when I go to press on one of my edit text elements, the keyboard still pops up. I only want the keyboard to pop up when I press a button. – user3781214 Jul 28 '14 at 18:58
-
Then use android:enabled="false" in the
if nothing it's suppose to happen when you press on it. And enable it after you press the button. – Goran Horia Mihail Jul 28 '14 at 19:05