Android AppCompatDialogFragment更改背景色
如何更改Android AppCompatDialogFragment更改背景色,android,appcompatdialogfragment,Android,Appcompatdialogfragment,如何更改AppCompatDialogFragment的背景色 我的类是extendsAppCompatDialogFragment,我不知道如何更改所有对话框的属性背景色 public class MyClassName extends AppCompatDialogFragment { ...} 您可以使用关于使背景透明和将透明更改为颜色的相同方法 创建onCreateView并在内部添加以下行:getDialog().getWindow().setBackgroundDrawable(新
AppCompatDialogFragment
的背景色
我的类是extendsAppCompatDialogFragment
,我不知道如何更改所有对话框的属性背景色
public class MyClassName extends AppCompatDialogFragment { ...}
您可以使用关于使背景透明和将透明更改为颜色的相同方法 创建
onCreateView
并在内部添加以下行:getDialog().getWindow().setBackgroundDrawable(新的ColorDrawable(Color.YELLOW))代码>
将Color.YELLOW
更改为所需的背景色
完整示例:
public class ClassName extends AppCompatDialogFragment {
...
...
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
return super.onCreateView(inflater, container, savedInstanceState);
}
}
如果要从颜色资源中选择颜色,请使用:
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(getContext().getColor(R.color.colorPrimary)));
WAREcolorPrimary
是颜色资源名称