android-dialog

Android DialogFragment vs Dialog

谁都会走 提交于 2019-11-26 09:28:53
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? PJL 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 ways of doing it but I simply define a message Handler in my Fragment , pass it into the DialogFragment

Android 'Unable to add window — token null is not for an application' exception

走远了吗. 提交于 2019-11-26 09:25:35
问题 I get the following Android exception when I try to open a dialog. Can someone please help me understand what is going on and how can I fix this problem? android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application at android.view.ViewRoot.setView(ViewRoot.java:509) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) at android.app.Dialog.show(Dialog.java:241)

How to make custom dialog with rounded corners in android

心已入冬 提交于 2019-11-26 09:16:39
问题 What I am trying to do: I am trying to make a custom dialog in android With rounded corners. What is happening: I am able to make custom dialog but it doesn\'t have rounded corners. I tried adding a selector but still I couldn\'t achieve rounded corners. Below is my code for the same: Java code: private void launchDismissDlg() { dialog = new Dialog(getActivity(), android.R.style.Theme_Dialog); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dlg_dismiss);

Get date from datepicker using dialogfragment

拈花ヽ惹草 提交于 2019-11-26 09:06:51
问题 I\'m using the google example to insert a datepicker inside my app using a dialogfragment http://developer.android.com/guide/topics/ui/controls/pickers.html But I\'m not sure how to get date after set it (not java expert). Dialog and datepicker runs ok and I can log that date is correctely set but, how can i do to get a callback executed on parent activity? This is my Dialog fragment public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {

Change background of ProgressDialog

孤者浪人 提交于 2019-11-26 08:16:44
问题 I am trying to change the background of a ProgressDialog . I searched the net and found various suggestions (like How to remove border from Dialog?), but I am unable to replace the actual background of the ProgressDialog . Instead I get another background (yellow) behind the dialog: My style: <style name=\"StyledDialog\" parent=\"@android:style/Theme.Dialog\"> <item name=\"android:windowBackground\">@drawable/panel_background</item> </style> The code that launches the ProgressDialog :

How to create a number picker dialog?

▼魔方 西西 提交于 2019-11-26 08:07:45
问题 I want to be able to create a Dialog that allows the user to pick a number from a specified range. I know that there are existing widgets(like those from quietlycoding and the one by SimonVT) that already does this but I\'m having hard time integrating those properly into my application. Also, those are primarily widgets. I want something that is very similar to the one in the android developers page tutorials. I also checked the documentation for the NumberPicker and it said to go check the

How to set DialogFragment&#39;s width and height?

自作多情 提交于 2019-11-26 04:58:57
问题 I specify the layout of my DialogFragment in an xml layout file (let\'s call it layout_mydialogfragment.xml ), and its layout_width and layout_height attributes particularly (to be 100dp each let\'s say). I then inflate this layout in my DialogFragment\'s onCreateView(...) method as follows: View view = inflater.inflate(R.layout.layout_mydialogfragment, container, false); Unfortunately, I find that when my dialog (DialogFragment) appears, it does not respect the layout_width and layout_height

How to dismiss the dialog with click on outside of the dialog?

二次信任 提交于 2019-11-26 03:25:02
问题 I have implemented a custom dialog for my application. I want to implement that when the user clicks outside the dialog, the dialog will be dismissed. What do I have to do for this? 回答1: You can use dialog.setCanceledOnTouchOutside(true); which will close the dialog if you touch outside of the dialog. Something like, Dialog dialog = new Dialog(context) dialog.setCanceledOnTouchOutside(true); Or if your Dialog in non-model then, 1 - Set the flag- FLAG_NOT_TOUCH_MODAL for your dialog's window

How to dismiss the dialog with click on outside of the dialog?

白昼怎懂夜的黑 提交于 2019-11-26 03:16:36
I have implemented a custom dialog for my application. I want to implement that when the user clicks outside the dialog, the dialog will be dismissed. What do I have to do for this? You can use dialog.setCanceledOnTouchOutside(true); which will close the dialog if you touch outside of the dialog. Something like, Dialog dialog = new Dialog(context) dialog.setCanceledOnTouchOutside(true); Or if your Dialog in non-model then, 1 - Set the flag- FLAG_NOT_TOUCH_MODAL for your dialog's window attribute Window window = this.getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,

Dialog with transparent background in Android

让人想犯罪 __ 提交于 2019-11-26 03:16:14
问题 How do I remove the black background from a dialog box in Android. The pic shows the problem. final Dialog dialog = new Dialog(Screen1.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.themechanger); 回答1: Add this code dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); Or this one instead: dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 回答2: <style name="NewDialog"> <item