i want to disable navigation bar in my app.i have use below code for it.it disable back button.now i want to disable home button when click on toggle button.how to disable home button using toggle button
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK ) {
//preventing default implementation previous to
//android.os.Build.VERSION_CODES.ECLAIR
return false;
}
return super.onKeyDown(keyCode, event);
}
You can't disable the home button.
But there is a workaround: Start your app again as soon as another app is launched.
See http://www.andreas-schrade.de/2015/02/16/android-tutorial-how-to-create-a-kiosk-mode-in-android/
Related
I've got a Samsung tablet SM-T560 on which when pressing the touch 'menu' key (next to the hardware 'home' button) opens the system menu for 'Active apps' where you can close or navigate to a previously opened app.
How can i override this functionality?I want to disable showing active apps upon this menu button click.
you need to override the menu button using the onKeyDown(int, KeyEvent) method in your activity. The following code snippet should be a good start for you:
#Override
public boolean onKeyDown(int keycode, KeyEvent event) {
switch(keycode) {
case KeyEvent.KEYCODE_MENU:
//Your functionality here
return true;
}
return super.onKeyDown(keycode, event);
}
Let's say I have an activity A that overrides the back button to show some dialog and that this activity has a menu.
So, when the back button is pressed the dialog shows up, but if the user press the menu button and then the back button, the dialog isn't shown. How can I make the behavior for the back button be the same whether the menu is visible or not?
You need to override the BackButton.
onBackPressed()
{
closeOptionsMenu(); // to close the Options Menu if it is visible
//your code here
}
protected boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
}
return true;
}
hope this help
I want to press hardware button Next will show Next Screen and press hardware button Pre will show Pre Screen (ViewFliper)
What do you know event press hardware button Next and Pre in Android ?
How catch event press hardware button Next and Pre in Android ?
You can watch image at here: enter link description here
Thanks!
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
mViewFliper.showPrevious();
return true;
}
if (keyCode == KeyEvent.KEYCODE_MENU) {
mViewFliper.showNext();
return true;
}
return super.onKeyDown(keyCode, event);
}
Although I can not express enough how utterly horrible it is for an app to do something like that.
I am creating an Android application in my application all Activities (pages) have a Back button so by pressing I can go to previous page or another page.For going on another page I use startActivity() and finish().But when I press keyboard's Back Button it goes to page which was previously pushed in Activities Stack.And I want to synchronize Keyboard's Back button and My Activities Back button.
How can I do this Please Help..
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
//start youractivity or finish();
}
return super.onKeyDown(keyCode, event);
}
override this method on your activity
I'm working on making a game for the android, with a friend doing the artwork. My friend wants to do his own menu, as in, he made an image to be used as the menu.
My question is, is there a way to have onMenuOpened() activate upon pressing the menu button with no menu items in onCreateOptionsMenu(), and then from my SurfaceView class close the menu? Or simply, how can I do my own menu that's activated upon pressing the menu button?
You probably could use Activity onKeyDown() function and detects KeyEvent.KEYCODE_MENU and do what you want.
Your code should be something like:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
// Do your own menu here
return true;
}
return false;
}