2
我试图创建一个全屏(但状态栏必须仍然可见)与自定义透明(与此答案相同https://stackoverflow.com/a/29482234)的对话框,但我的背景是不透明的。具有透明背景的DialogFragment
我浪费了2天的时间尝试所有的解决方案,但它不会工作。我的目标是显示一个自定义暗色对话框(而不是默认的黑色)。上面的答案看起来像我所需要的,但我无法实现它的工作。有什么建议么?
我的代码:
<style name="CustomDialogTheme2" parent="@android:style/Theme.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#AAFFFFFF">
<RelativeLayout
android:id="@+id/dialog_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#CCFF0000"
android:padding="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</RelativeLayout>
</FrameLayout>
DialogFragment:
public class TestDialogFrag extends DialogFragment {
public static TestDialogFrag newInstance() {
Bundle args = new Bundle();
TestDialogFrag fragment = new TestDialogFrag();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomDialogTheme2);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.test_dialog_frag, container, false);
return view;
}
}
你有没有尝试过呢? @ fanboy555 – MathaN