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.

有帮助吗?

解决方案

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.

其他提示

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
  }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top