I have gone through many of the suggestion for this in stack and couldn't still resolve my issue. I was using a Dialog fragment TestFragment
which is getting called from my AFragment
class and the TestFragment
is shown on top of the AFragment
.Currently on clicking outside of the screen, I have to close the TestFragment
. currently it is not getting closed. please find the below code.
DialogFragment.getDialog().setCanceledOnTouchOutside(true); I'm getting the following error Non-static method 'getDialog()' cannot be referenced from a static context
-> Couldnt resolve with this solution also.
AFragment :
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
testfragment testfragments = new testfragment();
testfragments.getDialog().setCanceledOnTouchOutside(true);
ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
ft.addToBackStack("filterPriceFragment");
ft.replace(R.id.filter_pop_up_frame_lyt, testfragments, "filterPriceFragment");
ft.commitAllowingStateLoss();
TestFragment
:
public class testfragment extends DialogFragment {
@Nullable
@org.jetbrains.annotations.Nullable
@Override
public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
final Context contextThemeWrapper = new ContextThemeWrapper(getContext(), R.style.MyApplyButton);
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
View view = localInflater.inflate(R.layout.filter_price_fragment_lyt, container, false);
return view;
}
}