How to make this simple portion of the dialog translucent

I am trying to make this simple dialog translucent:

class TestDialog extends SherlockDialogFragment { public TestDialog() { super(); } @Override public Dialog onCreateDialog(Bundle savedInstanceStateBundle ) { AlertDialog.Builder builder1 = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater1 = getActivity().getLayoutInflater(); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder1.setView(inflater1.inflate(R.layout.dlg_test, null)) // Add action buttons .setPositiveButton( "Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // sign in the user ... } }) .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); return builder1.create(); } } 

The layout is as follows:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/test" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/username" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_marginBottom="4dp" android:hint="User name" /> </LinearLayout> 

I tried everything: from using transparent .png as the background extracted from the linear layout, to set the alpha field to 0.5, to use as the color equal to 0. I cannot make this dialog translucent. I do not know, even if it is possible. What I would like to create is a dialog box similar to the panel in the following image: semi-transparent control panel . Thank you Note1: the required min sdk is version 8, the goal is the last (in fact, v17).

+6
source share
6 answers

Instead:

 return builder1.create(); 

Try to put this:

 Dialog dialog = builder1.create(); Drawable d = new ColorDrawable(Color.BLACK); d.setAlpha(130); dialog.getWindow().setBackgroundDrawable(d); return dialog; 
+5
source
 @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); return dialog; } 

You can put

 getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 

in the onCreateView dialog box.

+1
source

You can try either of these two topics in the link to your dialog.

 yourdialogFragment.setStyle(style,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); 

or

 yourdialogFragment.setStyle(style,android.R.style.Theme_Holo_Light_Dialog); 

Hope this helps.

0
source

You can try to make a transparent background, use this if you are a super class - this is the dialog:

 getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 

or this if your superclass is interactive:

 getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 

Another solution was similar to "kaushal trivedi". Using DialogFragments:

 public class MyDialogFragment extends DialogFragment { ... @Override public void onCreate(Bundle savedInstance){ super.onCreate(savedInstance); setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.my_dialog, container,false); } } 

This makes your dialog fullscreen and without background, so you can put whatever you want into it.

0
source

try it

 public class Dialogs extends DialogFragment { public Dialogs() { } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style. Theme_WallpaperSettings); } } 
0
source

This is what I did to achieve transparency with AlertDialog.

Custom style created:

 <style name="TranslucentDialog" parent="@android:style/Theme.DeviceDefault.Dialog.Alert"> <item name="android:colorBackground">#32FFFFFF</item> </style> 

And then create a dialog with:

 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.TranslucentDialog); AlertDialog dialog = builder.create(); 

Link to my answer to the corresponding question: fooobar.com/questions/39054 / ...

0
source

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


All Articles