Android: Custom AlertDialog

I created a special alertdialog with 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(); 

The problem is that the popup is surrounded by the background of the dialog having its own empty title space (since the title is not set). How to remove it. I tried to set a custom style via ContextThemeWrapper as builder = new AlertDialog.Builder(new ContextThemeWrapper(getParent(), R.style.CustomDialogTheme));

But it does not work. How can I do it?!!! Thanks in advance. Custom xml style is below:

 <style name="CustomDialogTheme" parent="android:style/Theme.Dialog.Alert"> <item name="android:windowIsFloating">false</item> <item name="android:windowNoTitle">true</item> </style> 

This is the output on the emulator

+6
source share
2 answers

use the following

 Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar); 

Fill the layout and set the view to the content of the dialogue and

 dialog.setContentView(view); 
+16
source
 AlertDialog dialog = new AlertDialog.Builder(this) .setView(getLayoutInflater().inflate(R.layout.custom_dialog, null)) .create(); 

To listen to user interface 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(); 
+7
source

Source: https://habr.com/ru/post/906533/


All Articles