Alert Dialog with setCancleable(false) I cannot show the Menu - android

I use modal alert dialogs by calling setCancelable(false); By doing this the BACK hardware button is disabled. But unfortunately this is also true for the MENU hardware button. So the user does not have access to the option menu. I am using a Samsung Galaxy Tab3 with Android 4.4.2
How can I change this? Alternatively: Is there a possibility to catch the BACK button pressed event in a DialogFragment?

Something like this might do the trick :
#Override
public boolean onKeyDown(int keycode, KeyEvent e) {
switch(keycode) {
case KeyEvent.KEYCODE_MENU:
doSomething();
return true;
}
return super.onKeyDown(keycode, e);
}
(See more here : Android: How to add listener to hardware menu button?)

Related

Android Studio.How to disable all system buttons(Back, Home and Menu) for activity?

I have seen many solutions to this problem, but the solutions were for older versions. Is there any way to disable the system buttons Back, Home and Menu for one activity? I am programming for android 7 and above.
You can try override onKeyDown.This can intercept back button and do something you want.Also override onBackPressed() can intercept back button.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
do something;
return true;
}
return false;
}
But the menu button and home button I'm not sure if still can intercept in now days.
You can try to lock the com.android.systemui package

Android - menu button opens system active apps

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);
}

Overriding back button press from Activity's subClass in Android

I'm making a game with OpenGL Es 1.1 and i want to implement back button or menu button functionality to my game.(I mean hardware buttons).I have some subClasses so what i have to do when i want to handle hardware button press from subClasses?
You need to implement an onKeyDown listener and check to see what key is pressed.
Sample:
#Override
public boolean onKeyDown(int keycode, KeyEvent e) {
switch(keycode) {
case KeyEvent.KEYCODE_MENU:
handleMenuButton();
return true;
case KeyEvent.KEYCODE_BACK:
handleBackButton();
return true;
}
return super.onKeyDown(keycode, e);
}
Also note that for the back and menu buttons to fire reliably, you need to set setFocusableInTouchMode to true. See the devguide here (scroll down to "Touch Mode").

Making a Custom Menu in Android

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;
}

What is the command to return to your main screen in an app?

How do I have an app return to the 'Home' screen when the user is on a different class and they click the back/return button on their phone?
Right now, when they access a different class and hit the back button, it goes back to the Home screen on the Droid rather than the Home screen on the app - how do I get it to go back to the Home Screen on the app?
Thanks!
Use OnBackPressed() method of Activity class.
Make conditions like :
public void onBackPressed(){
if(conditon)
{
detailInfoList.setVisibility(View.VISIBLE);//or anything that you want to show
}
}
you can't,
the home button is the only you can't prevent form closing your app. Its done so that you can't block the user inside your applications (like a virus).
the other keys like back menu and research are possible
in your activity
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
if(keyCode == 82){
Log.i("jason","released on menu");
//change view
//return so that the other behavior (leaving the activity) is not tirggered
return false;
}
}
Log.i("jason","actual key code "+keyCode);
return super.onKeyDown(keyCode, event);
}

Categories

Resources