Reputation: 3917
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>
Upvotes: 6
Views: 20325
Reputation: 29199
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);
Upvotes: 16
Reputation: 8645
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();
Upvotes: 7