When a user presses the Search hard key on the device, Android shows the Quick Search Bar. How do I disable the Quick Search Bar?
override onKeyDown in your activity:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
return true;
} else return super.onKeyDown(keyCode, event);
}
In order to completely disabled the Quick Search Bar, override the method onSearchRequested()and return true unconditionally.
Related
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
...
return false;
}
Once the above method is added to an activity, the back button stops working but the other two buttons on the navigation bar - home and overview - still work perfectly.
Could anyone shed some light on this?
Because You're always returning false from it. It should actually be conditional & in other cases, you should call super.onKeyUp(keyCode, event);
Example:
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (condition == true){
//do something
return false;
}
return super.onKeyUp(keyCode,event);
}
While doing digits programming, i am using following method :
Digits.authenticate(authCallback,R.style.CustomDigitsTheme1);
which directs me to digits authentication screen(without showing my xml design file).
Now, when i press back button, it shows me my xml with digits auth button as below.
which i do not want.I tried conventional ways of disabling back buttons but they did not work. Is there any way i can disable back button on authentication???
You can override when the keyboard disappears using this method:
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK &&
event.getAction() == KeyEvent.ACTION_UP) {
// Do your thing here
return false;
}
return super.dispatchKeyEvent(event);
}
This may helps you.
Try Using these
#Override
public void onBackPressed() {
// your code.
}
and for older then API 5 use this:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// your code
return true;
}
return super.onKeyDown(keyCode, event);
}
Why when I press this button, a pop up (with text Settings) is displayed in my app ?
How can I remove it?
For handling this keys you need to override this method of the Activity
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode ==KeyEvent.KEYCODE_MENU) {
//return true if you want block button menu
return true;
}
return super.onKeyDown(keyCode, event);
}
I am new to android, I have a small doubt regarding how to handle the hardware Keyboard and if I click the search button in any part of my application it should be handled means I need to pass the intent of search activity?
How I can reach this goal.
Try this,
#Override
public boolean onSearchRequested() {
// your stuff here
return false;
}
It will also trigger onKeyDown with a keyCode of KeyEvent.KEYCODE_SEARCH before calling onSearchRequested as stated above
Add a listener for your EditText to listen on the Search button as following:
myEditText.setOnKeyListener(new OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_ENTER) {
//Do some stuff
}
//Leave the return value false to hide the SoftKeyboard if it is shown
return false;
}
});
For me, it happened before that the softkey search button is detected as Enter button not search. That's why I'm ORing them
How to capture when user presses "Search Soft key" in android.
Can we do it in onKeyDown() and checking the keycode?
Try this in your Activity code:
#Override
public boolean onKeyDown( int keyCode, KeyEvent event )
{
if ( event.getKeyCode() == KeyEvent.KEYCODE_SEARCH )
{
// Catch the search
// do something
// return true to consume press or false to pass it on
}
return super.onKeyDown( keyCode, event );
}
I think that you are right. You can check for the key code that is given in the following list.
And prefer to check this onKeyUp.
http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_SEARCH
I've done something like this for capturing the search softkey when progress dialog is showing and it worked fine for me:
progressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
#Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
return true;
}
return false;
}
});