Customised dialog can be created by usng two ways
by configuring it in styeable
<style name="myDialog" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
<style name="Theme.Holo.Dialog.NoActionBar.MinWidth">
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>
<style name="CustomDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@color/Black0Percent</item>
<item name="android:paddingTop">20dp</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowIsFloating">false</item>
</style>
// another way is by only using Dialog we can implement
private void showOTPDialog() {
final Dialog dialogOtp = new Dialog(this, R.style.myDialog);
dialogOtp.setContentView(R.layout.otp_field);
dialogOtp.setCancelable(true);
PinEntryEditText pinEntryEditText = dialogOtp.findViewById(R.id.txt_pin_entry);
Button buttonVerify = dialogOtp.findViewById(R.id.verifybtn);
buttonVerify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialogOtp.dismiss();
}
});
//now that the dialog is set up, it's time to show
try {
dialogOtp.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public class OtpDialog extends DialogFragment {
private PinEntryEditText pinEntryEditText;
private Button buttonVerify;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.otp_field, null);
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
/*frag.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Dialog_NoTitle);*/
int width = getResources().getDimensionPixelSize(R.dimen.otp_dialog_width);
int height = getResources().getDimensionPixelSize(R.dimen.otp_dialog_height);
getDialog().getWindow().setLayout(width, height);
pinEntryEditText = view.findViewById(R.id.txt_pin_entry);
buttonVerify = view.findViewById(R.id.verifybtn);
return view;
}
// add this on onStart
@Override
public void onStart() {
super.onStart();
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, (int) getResources().getDimension(R.dimen.dialog_height));
}
}
new OtpDialog().show(getFragmentManager(),null);