android-dialog

How can I add a third button to an Android Alert Dialog?

感情迁移 提交于 2019-12-18 10:11:14
问题 The API says that the Alert Dialog can have one, two or three buttons, but the SDK only allows for a positive and negative button. How then can I add a third button? 回答1: This code snippet should help explain the three different buttons you can use: alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Dialog Button"); alertDialog.setMessage("This is a three-button dialog!"); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Button 1 Text", new DialogInterface

Softkeyboard not showing in AlertDialog for phone only

独自空忆成欢 提交于 2019-12-18 09:18:50
问题 Why the softkeyboard is showing only on the tablet is a mystery ! Here is the code that I have used. AlertDialog.Builder builder = new AlertDialog.Builder(CurrentActivityName.this); builder.setTitle(“Title”); builder.setMessage(“Message”); final EditText input = new EditText(CurrentActivityName.this); builder.setView(input); builder.setPositiveButton(R.string.allow, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //my code } });

How to get dialog size?

社会主义新天地 提交于 2019-12-18 07:37:28
问题 I am looking for a way to get size of a custom dialog. I went through this question, but the only answer given is pretty useless, because if I try mDialog.getWindow().getAttributes().height; it only returns -2, which is a constant for WRAP_CONTENT attribute which I set to dialog. How can I get the size of it. I want to know the siye for the background image. 回答1: Actually, in Android it doesn't work like in iOS - you can't get the size of the View itself, what you can do, though, is to ask

Android 6.0 Dialog text doesn't appear

末鹿安然 提交于 2019-12-18 03:03:10
问题 I updated my phone to Android 6.0 and I have these 2 problems with dialogs: 1)The title is shown but the messages isn't for alert dialog(SOLVED): new AlertDialog.Builder(context).setTitle("Title").setMessage("Message"); 2)Also custom dialog fragment's title is not shown(NOT SOLVED): getDialog().setTitle("Title"); There was not such a problem in lollipop or in older versions, the problem appeared only after updating my phone to marshmallow. How to solve the problem? 回答1: Use constructor with

Show dialog from fragment?

别来无恙 提交于 2019-12-17 08:09:46
问题 I have some fragments that need to show a regular dialog. On these dialogs the user can choose a yes/no answer, and then the fragment should behave accordingly. Now, the Fragment class doesn't have an onCreateDialog() method to override, so I guess I have to implement the dialogs outside, in the containing Activity . It's ok, but then the Activity needs to report back the chosen answer somehow to the fragment. I could of course use a callback pattern here, so the fragment registers itself at

How do I maintain the Immersive Mode in Dialogs?

廉价感情. 提交于 2019-12-17 05:25:29
问题 How do I maintain the new Immersive Mode when my activities display a custom Dialog? I am using the code below to maintain the Immersive Mode in Dialogs, but with that solution, the NavBar appears for less than a second when I start my custom Dialog, then it disappears. The following video explains the issue better (look at the bottom of the screen when the NavBar appears): http://youtu.be/epnd5ghey8g How do I avoid this behavior? CODE The father of all activities in my application: public

How do I maintain the Immersive Mode in Dialogs?

自古美人都是妖i 提交于 2019-12-17 05:25:05
问题 How do I maintain the new Immersive Mode when my activities display a custom Dialog? I am using the code below to maintain the Immersive Mode in Dialogs, but with that solution, the NavBar appears for less than a second when I start my custom Dialog, then it disappears. The following video explains the issue better (look at the bottom of the screen when the NavBar appears): http://youtu.be/epnd5ghey8g How do I avoid this behavior? CODE The father of all activities in my application: public

findViewById() returns null for Views in a Dialog

廉价感情. 提交于 2019-12-17 04:08:27
问题 The problem is, no matter where or how I call for this layout's components, they always return null. setView(inflater.inflate(R.layout.search_layout, null)) This works fine. It displays the layout inside the Dialog , yet, the children are always returned as null by findViewById(R.id.some_search_layout_children) . I've tried cleaning my project multiple times, tried to implement another class for my Dialog , called findViewById() as a member of my main Activity , inside the initSearch() method

How to display progress dialog before starting an activity in Android?

核能气质少年 提交于 2019-12-17 02:36:11
问题 How do you display a progress dialog before starting an activity (i.e., while the activity is loading some data) in Android? 回答1: You should load data in an AsyncTask and update your interface when the data finishes loading. You could even start a new activity in your AsyncTask's onPostExecute() method. More specifically, you will need a new class that extends AsyncTask: public class MyTask extends AsyncTask<Void, Void, Void> { public MyTask(ProgressDialog progress) { this.progress = progress

Android DialogFragment vs Dialog

北城以北 提交于 2019-12-17 02:00:54
问题 Google recommends that we use DialogFragment instead of a simple Dialog by using Fragments API , but it is absurd to use an isolated DialogFragment for a simple Yes-No confirmation message box. What is the best practice in this case? 回答1: Yes, use DialogFragment and in onCreateDialog you can simply use an AlertDialog builder anyway to create a simple AlertDialog with Yes/No confirmation buttons. Not very much code at all. With regards handling events in your fragment there would be various