How to disable BottomSheetDialogFragment dragging

There is simpler way of achieving the same after material design 1.2.0 was released. https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetBehavior#setdraggable When calling from BottomSheetDialogFragment: override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog bottomSheetDialog.setOnShowListener { val bottomSheet = bottomSheetDialog .findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet) if (bottomSheet != null) { val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(bottomSheet) behavior.isDraggable = false } } return bottomSheetDialog …

Read more

Adding positive / negative Button to DialogFragment’s Dialog

This is how I figured it out. I erased the onCreateView and altered the onCreateDialog. This link actually had the answer so all the credit should go there. I’ve just posted it just in case anyone bumps in this question first. @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder b= new AlertDialog.Builder(getActivity()) .setTitle(“Enter Players”) .setPositiveButton(“OK”, new …

Read more

How do I fire an event when click occurs outside a dialog

When dialog.setCanceledOnTouchOutside(true); then you just override onCancel() like this: dialog.setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { //When you touch outside of dialog bounds, //the dialog gets canceled and this method executes. } } ); Type your code inside the onCancel() method so it runs when the dialog gets canceled.

Get date from datepicker using dialogfragment

Constructor fo DatePickerDialog takes DatePickerDialog.OnDateSetListener as second parameter, so maybe you should implement that interface in your parent activity EditSessionActivity (not in DatePickerFragment ) and change this line: return new DatePickerDialog(getActivity(), this, year, month, day); into this: return new DatePickerDialog(getActivity(), (EditSessionActivity)getActivity(), year, month, day); And then your activity should looks like this: public class EditSessionActivity …

Read more

How to create a number picker dialog?

I have made a small demo of NumberPicker. This may not be perfect but you can use and modify the same. public class MainActivity extends Activity implements NumberPicker.OnValueChangeListener { private static TextView tv; static Dialog d ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.textView1); Button b = (Button) findViewById(R.id.button11); b.setOnClickListener(new …

Read more

Android get full width for custom Dialog

You need to get the current Window and set it’s LayoutParams like so: Dialog d=new Dialog(mContext); ……… ……… myDialog.show(); Window window = myDialog.getWindow(); window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); Alternative(if above solution does’t works) In case above code not works well you can use a workaround styles.xml <style name=”mydialog”></style> Java Dialog d=new Dialog(mContext,R.style.mydialog); ……… ……… myDialog.show(); Window window = …

Read more