Frage

Is it possible to completely disable the settings key from the softkeyboard for an android app?

The button i want to disable is the second button on the left-bottom in the image:

Example

Now i have something like this:

userName = (EditText) findViewById(R.id.txt_name);
password = (EditText) findViewById(R.id.password);
userName.setOnKeyListener(this);
password.setOnKeyListener(this);

public boolean onKey(View v, int keyCode, KeyEvent event) {

switch (v.getId()) {
     case R.id.txt_name:
     if ((event.getAction() == KeyEvent.ACTION_DOWN)
     && (keyCode == KeyEvent.KEYCODE_SETTINGS)) {
        mUserName = userName.getText().toString();
        if (mUserName.equals("")) {
           Toast.makeText(this, "Enter user name...",
           Toast.LENGTH_SHORT).show();

     } else
     password.requestFocus();
     break
  }
}

unfortunately this code wont detect the settings key.

War es hilfreich?

Lösung

Is it possible to completely disable the settings key from the softkeyboard for an android app?

You can write your own input method editor (or modify the code for an existing one) that does not have this button. Putting this as the default keyboard in your custom ROM would then achieve your objective.

An SDK app, however, cannot disable this button or otherwise control the behavior of an input method editor in this fashion.

Andere Tipps

try onKeyDown in place of onKey . in your code for exemple :

@Override  
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (v.getId()) {
     case R.id.txt_name:
     if (keyCode == KeyEvent.KEYCODE_SETTINGS) {        
        mUserName = userName.getText().toString();
        if (mUserName.equals("")) {
           Toast.makeText(this, "Enter user name...",
           Toast.LENGTH_SHORT).show();

     } else
     password.requestFocus();
     break
  }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top