문제

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