I have created a custom alertdialog by the following code:
AlertDialog.Builder builder;
AlertDialog alertDialog;
LayoutInflater inflater = (LayoutInflater)ActivityName.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_layout,(ViewGroup)findViewById(R.id.layout_root));
builder = new AlertDialog.Builder(getParent());
builder.setView(layout);
alertDialog = builder.create();
alertDialog.show();
Problem is the pop up is surrounded with the default Dialog background having a own void space of a title(as the title is not set). How do i remove this. I have tried putting custom style through ContextThemeWrapper
like
builder = new AlertDialog.Builder(new ContextThemeWrapper(getParent(), R.style.CustomDialogTheme));
But its not working. How do i do that?!!! Thanks in Advance. Custom style xml is given below:
<style name="CustomDialogTheme" parent="android:style/Theme.Dialog.Alert">
<item name="android:windowIsFloating">false</item>
<item name="android:windowNoTitle">true</item>
</style>
If you want a custom layout in a dialog, create a layout and add it to an AlertDialog by calling setView() on your AlertDialog. Builder object. By default, the custom layout fills the dialog window, but you can still use AlertDialog. Builder methods to add buttons and a title.
The custom dialog uses DIALOG to create custom alert in android studio. Dialog display a small window i.e a popup which draws the user attention over the activity before they continue moving forward. The dialog appears over the current window and display the content defined in it.
Open Android Studio and import the starter project. Create a new class CustomDialog. kt to contain our dialog. Our CustomDialog is initialized with a context as it is needed by AlertDialog.
There are two types of dialogs: basic and full-screen.
use following
Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar);
Inflate your layout and set the view to content of dialog and
dialog.setContentView(view);
AlertDialog dialog = new AlertDialog.Builder(this)
.setView(getLayoutInflater().inflate(R.layout.custom_dialog, null))
.create();
In order to listen for UI events:
View view = getLayoutInflater().inflate(R.layout.custom_dialog, null);
Button btn = (Button)view.findViewById(R.id.the_id_of_the_button);
btn.setOnClickListener(blah blah);
AlertDialog dialog = new AlertDialog.Builder(this)
.setView(view)
.create();
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