This question already has answers here:
How to show a dialog to confirm that the user wishes to exit an Android Activity?
(11 answers)
Closed 9 years ago.
When the user clicks the back button on the main activity, I would like a dialog to pop up asking the user if he "wants to leave". I am able to create the dialog and implement it but I am unsure of how to make the dialog open when the back button is pressed. Any Suggestions?
Which API? This is the easiest way from API 5+
#Override
public void onBackPressed () {
//super.onBackPressed();
dialog.show();
}
Related
This question already has answers here:
How can I add some sound to my Java JFrame? [closed]
(1 answer)
Java :Painting Random Shapes on JFrame against Music Played
(1 answer)
Closed 7 months ago.
I am building a simple calculator project in Java using Swing and I want to play a sound when the user clicks on the buttons in the app. I don't know how to achieve this.
All you need to do is implement an OnTouchListener
on the button and use the AudioManager.playSoundEffect() public method. Code is shown below:
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
float vol = 0.5; //This will be half of the default system sound
am.playSoundEffect(AudioManager.FX_KEY_CLICK, vol);
This question already has answers here:
Disable keyboard on EditText
(18 answers)
Closed 1 year ago.
I am trying to create calculator application in Android Studio using Java, I have EditText for showing result. When I focus this input Keyboard is showing. But I don't want to see keyboard in focus event as in normal calculator. Is there any way to solve this, or can I use other element either than EditText, I have used getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); in OnCreate method, but it doesn't work
EditText is desired to.. edit text. do you want to allow user for editing result?
if not just replace EditText with TextView and then any keyboard won't show up
if you still want this field to be editable then take a look a THIS QA, you will find there plenty of methods for blocking keyboard pop up automatically
This question already has answers here:
Android - How To Override the "Back" button so it doesn't Finish() my Activity?
(10 answers)
Closed 5 years ago.
I have a recyclerView in a fragment which I use it to show some items. When selecting these items I change my toolbar title to number of selected items and also I change menu options. how can I make pressing back button cancel the selection operation?
You override the
onBackPressed()
Method and do what you want there. Any back key press will trigger this function and you'll be able to use your logic
This question already has answers here:
Android Edittext question, replace keypad enter with done
(5 answers)
Closed 5 years ago.
I made an app with several EditTexts in my layout, and when I enter Something into the first, the keyboard will show a "next" arrow, to type in the next EditText. But I don't want that to happen. I want it to show a "finished" symbol, and exit the keyboard when I press it. How can I do that?
Add android:imeOptions="actionDone" to your EditText to acheive this.
This question already has answers here:
Disable Screenshot of my Swing Window
(5 answers)
Closed 9 years ago.
Can I disable the print screen button, while my application is on? Can we use the print screen button as one of the coded keyboard inputs, and equal it to do nothing?
There's no way to do this without affecting the Operating System settings via registry edits, etc.
A user can always unfocus your application, and press print screen taking a capture of the whole screen otherwise.