How to remove black border from AlertDialog builder

In fact, I created a custom dialog using AlertDialog.builder. In this dialog box, I do not show titile. Everything works fine, but a black frame appears in the dialog box. Can I tell you how I can remove this black boder. The code and screenshot are below.

code in java:

AlertDialog.Builder start_dialog = new AlertDialog.Builder(this); Context mContext = getApplicationContext(); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.custom_dialog2, (ViewGroup) findViewById(R.id.layout_root)); layout.setBackgroundResource(R.drawable.img_layover_welcome_bg); Button btnPositiveError = (Button)layout.findViewById(R.id.btn_error_positive); btnPositiveError.setTypeface(m_facedesc); start_dialog.setView(layout); final AlertDialog alert = start_dialog.create(); alert.show(); btnPositiveError.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { alert.dismiss(); } }); 

Scrrenshot

enter image description here

+4
source share
5 answers
 Without creating a custom background drawable and adding a special style just add 

one line to your code:

 dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 

More about dialogs:

Dilaogs

+6
source

Change this line of code

 AlertDialog.Builder start_dialog = new AlertDialog.Builder(this); 

to

 AlertDialog.Builder start_dialog = new AlertDialog.Builder(this).setInverseBackgroundForced(true); 

everything will be installed

+2
source

Use Dialog class instead of AlertDialog

 for eg - Dialog d = new Dialog(context, android.R.style.Theme_Translucent); 

use setContentView instead of setView.

And set your theme transparent.

0
source

Just you insert

 Dialog start_dialog = new Dialog(this); 

instead of this

 AlertDialog.Builder start_dialog = new AlertDialog.Builder(this); 
0
source

I also had this problem. It is better to use Dialog instead of AlertDialog . This is my decision:

 Dialog dialog = new Dialog(getActivity(), R.style.Dialog_No_Border); dialog.setContentView(R.layout.some_dialog); 

Contents of some_dialog.xml

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="250dp" android:layout_height="350dp" android:orientation="vertical" android:background="@drawable/some_dialog_background"> <TextView ... /> <Button ... /> </LinearLayout> 

styles.xml

 <style name="Dialog_No_Border" parent="@android:style/Theme.Dialog"> <item name="android:windowIsFloating">true</item> <item name="android:windowBackground">@color/transparent_color</item> </style> 

So finally, I have my own dialogue with a background without borders.

0
source

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


All Articles