android 中的圆角对话框
Dialog with rounded corner in android
I have gone through some solutions but none solve my issue.
我创建了一个自定义 DialogFragment
。和 dialog is cardView
的根元素。我设置 cardCornerRadius
共 cardView
。
然后我尝试设置透明对话框,因为背景颜色也随之显示。
然后我尝试将对话主题设置为
<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);
尝试在 parent 样式中使用无标题栏主题并使其半透明:
<style name="PauseDialog" parent="@android:style/Theme.NoTitleBar">
....rest of your style
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
如果您想要圆角,您可以尝试使用 xml 将自定义形状应用于您的自定义对话框背景。以下代码将帮助您。
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners
android:radius="10dp"/>
</shape>
您可以删除 cardview 作为顶部元素,因为对话框有它的阴影和深度。
在将 contentview 设置为 dialog
之前添加此行
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
我来晚了,但已经解决了你的问题。只需在您的样式文件中使用 android:dialogCornerRadius
。
在你的 values/styles:
中像这样使用它
<item name="android:dialogCornerRadius">20dp</item>
如果您想设置整个应用程序的圆角半径,则可以将此行粘贴到 values/themes/themes.xml。它将在您的整个应用程序对话框中设置圆角半径。
<item name="dialogCornerRadius">10dp</item>
I have gone through some solutions but none solve my issue.
我创建了一个自定义 DialogFragment
。和 dialog is cardView
的根元素。我设置 cardCornerRadius
共 cardView
。
然后我尝试设置透明对话框,因为背景颜色也随之显示。
然后我尝试将对话主题设置为
<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);
尝试在 parent 样式中使用无标题栏主题并使其半透明:
<style name="PauseDialog" parent="@android:style/Theme.NoTitleBar">
....rest of your style
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
如果您想要圆角,您可以尝试使用 xml 将自定义形状应用于您的自定义对话框背景。以下代码将帮助您。
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners
android:radius="10dp"/>
</shape>
您可以删除 cardview 作为顶部元素,因为对话框有它的阴影和深度。 在将 contentview 设置为 dialog
之前添加此行dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
我来晚了,但已经解决了你的问题。只需在您的样式文件中使用 android:dialogCornerRadius
。
在你的 values/styles:
中像这样使用它<item name="android:dialogCornerRadius">20dp</item>
如果您想设置整个应用程序的圆角半径,则可以将此行粘贴到 values/themes/themes.xml。它将在您的整个应用程序对话框中设置圆角半径。
<item name="dialogCornerRadius">10dp</item>