I have gone through some solutions but none solve my issue.
我创建了一个自定义 DialogFragment
。 dialog 的根元素是 cardView
。我设置了 cardView
的 cardCornerRadius
。
然后我尝试设置透明对话框,因为背景颜色也随之显示。
然后我尝试将对话框主题设置为
<style name="PauseDialog" parent="@style/Theme.AppCompat.Light.Dialog">
<!-- TTheme.AppCompat.Translucent-->
<item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
<!--<item name="android:windowBackground">@android:color/transparent</item>-->
<item name="android:windowBackground">@color/transparent</item>
<item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">@android:color/transparent</item>
</style>
背景仍然存在。然后我也试了
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(Color.TRANSPARENT));
但对话框仍然有与之关联的背景。
Is there any work around. How could i get rid of it.
我创建了一个 DialogFragment 并在 onCreateDialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
R.style.PauseDialog);
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.PauseDialog);
最佳答案
如果您想要圆角,您可以尝试使用 xml 将自定义形状应用于您的自定义对话框背景。以下代码将帮助您。
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners
android:radius="10dp"/>
</shape>
您可以删除 cardview 作为顶部元素,因为对话框有它的阴影和深度。 在将 contentview 设置为对话框之前添加此行
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
关于android - android中带圆角的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36309123/