简体   繁体   English

"android中带圆角的对话框"

[英]Dialog with rounded corner in android

I have gone through some solutions but none solve my issue.我已经通过了一些解决方案,但没有一个解决我的问题。

<\/blockquote>

I have created a custom DialogFragment<\/code> .我创建了一个自定义DialogFragment<\/code> 。 and root element of dialog is cardView<\/code> . dialog is cardView<\/code> 。 I set cardCornerRadius<\/code> of cardView<\/code> .我设置了cardCornerRadius<\/code>的cardView<\/code> 。

Then i try to set Transparent Dialog because background color is also showing with it.然后我尝试设置透明对话框,因为背景颜色也随之显示。

then i try to set the dialog theme like然后我尝试设置对话框主题

<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><\/code><\/pre>

The background still remains there.背景仍然存在。 And then I also tried然后我也尝试了

dialog.getWindow().setBackgroundDrawable( new ColorDrawable(Color.TRANSPARENT));<\/code><\/pre>

but still dialog have background associated with it.但对话框仍然有与之关联的背景。

Is there any work around.有什么解决办法。 How could i get rid of it.我怎么能摆脱它。

<\/blockquote>

I have created a DialogFragment<\/strong> and in onCreateDialog<\/code>我创建了一个DialogFragment<\/strong>并在onCreateDialog<\/code>

 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.PauseDialog); setStyle(DialogFragment.STYLE_NO_FRAME, R.style.PauseDialog);<\/code><\/pre>

在此处输入图像描述<\/a>

"

If you want rounded corner you can try apply custom shape using xml to your custom dialog backgroud. 如果您想要圆角,可以尝试使用xml将自定义形状应用于自定义对话框背景。 Following code will help you out. 以下代码将帮助您。

<shape xmlns:android="http://schemas.android.com/apk/res/android">

     <solid android:color="#FFFFFF" />
        <corners
            android:radius="10dp"/>

    </shape>

You can remove cardview as top element because dialog has its on shadow and depth. 您可以删除cardview作为顶部元素,因为对话框具有阴影和深度。 Add this line before you set contentview to dialog 在将contentview设置为对话框之前添加此行

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

Try use in parent style a no title bar theme and make it translucent: 尝试在父样式中使用无标题栏主题并使其半透明:

<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>

I arrived late but with the solution to your question.我来晚了,但解决了你的问题。 just use the android:dialogCornerRadius in your style file.只需在您的样式文件中使用android:dialogCornerRadius

Use it like this in your values/styles:在你的价值观/风格中像这样使用它:

<item name="android:dialogCornerRadius">20dp</item>
        

If you want to set corner radius of your whole app then you can paste this line in values\/themes\/themes.xml.如果要设置整个应用程序的角半径,则可以将此行粘贴到 values\/themes\/themes.xml 中。 It will set corner radius on your whole app dialogs.它将在您的整个应用程序对话框中设置角半径。

<item name="dialogCornerRadius">10dp</item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM