I started a DialogFragment from ActivityA, When i click on the white background of DailogFragment where there are no elements, the click event is happening on the ActivityA which is in background
public class FilterDialog extends DialogFragment{
private static final String TAG = "FilterDialog";
Calendar myCalendar = Calendar.getInstance();
private String stringDate;
DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
monthOfYear++;
stringDate = dayOfMonth+"-"+ monthOfYear +"-"+year;
}
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.dialog_filter, container, false);
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
toolbar.setTitle("Filter");
Button datePicker = (Button) rootView.findViewById(R.id.datePicker);
View.OnClickListener datePickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
if(v.getId() == R.id.datePicker){
new DatePickerDialog(v.getContext(), date,
myCalendar.get(Calendar.YEAR),
myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
}
};
datePicker.setOnClickListener(datePickListener);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setHomeAsUpIndicator(android.R.drawable.ic_menu_close_clear_cancel);
}
return rootView;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
@Override
public void onStart()
{
super.onStart();
final AlertDialog d = (AlertDialog)getDialog();
if(d != null)
{
Button positiveButton = (Button) d.getButton(Dialog.BUTTON_POSITIVE);
positiveButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Boolean wantToCloseDialog = false;
if(wantToCloseDialog)
d.dismiss();
}
});
}
}
}
This is my DialogFragment, to show dialogfragment i used
FragmentManager fragmentManager = getSupportFragmentManager();
FilterDialog newFragment = new FilterDialog();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.replace(android.R.id.content, newFragment).addToBackStack(null).commit();
screenshot
As shown in the above screenshot, If i click on any of the highlighted color, click is happening on ActivityA which is in background and not visible. Can anyone help me to disable this.
Stay organized with collections Save and categorize content based on your preferences. This class was deprecated in API level 28.
Dialog: A dialog is a small window that prompts the user to make a decision or enter additional information. DialogFragment: A DialogFragment is a special fragment subclass that is designed for creating and hosting dialogs.
Show activity on this post. tl;dr: The correct way to close a DialogFragment is to use dismiss() directly on the DialogFragment.
you can set your args. class IntervModifFragment : DialogFragment(), ModContract. View { companion object { fun newInstance( plom:String,type:String,position: Int):IntervModifFragment { val fragment =IntervModifFragment() val args = Bundle() args. putString( "1",plom) args.
Make android:clickable=true
for the root layout of that dialog.
You have set setCancelable(false);
in onCreateView
method, next to the inflate line as below
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.dialog_filter, container, false);
setCancelable(false);
}
Hope this is helpful :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With