【发布时间】:2016-08-03 06:32:01
【问题描述】:
我正在尝试创建一个全屏(但状态栏必须仍然可见)自定义透明对话框(与此答案 https://stackoverflow.com/a/29482234 相同),但我的背景不透明。
我已经浪费了 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>
对话框片段:
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;
}
}
【问题讨论】:
标签: android android-dialogfragment android-dialog