I\'m building a custom DialogFragment
. The dialog layout is set to my_dialog.xml
, but how can I modify the color around the dialog (the transparent
To get a fully transparent dialog, you can set in onCreateView
the following
setBackgroundDrawable
to Color.TRANSPARENT
setDimAmount
to 0
See code example here:
public class TextEditor extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_text_editor, container);
// make dialog itself transparent
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// remove background dim
getDialog().getWindow().setDimAmount(0);
//[add more custom code here...]
return view;
}
}
change your Text Background
on the XML
i just edited your code replace it with yours
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<TextView
android:id="@+id/hello"
android:layout_width="100dp"
android:layout_height="100dp"
android:gravity="center"
android:text="hello" />
because you gave the TextView
height and width of 100dp. and set a background for it that will fill the whole dialog. since your main layout is wrap_content.
please do accept the answer if that helped you.
Edit : to change the background
just add to your layout or to your textview
android:background="#232323"
you can change these number to any color you like. or you can set a background from the drawable
like android:background="@drawable/yourpicturename"