繁体   English   中英

android-如何使用材质设计进行自定义对话框

[英]android - How use material design for custom dialog

我想为对话框使用自定义视图,但是问题是当我使用自定义布局时,我没有得到漂亮的布局。 这是我的代码的结果:

在此处输入图片说明

如您所见,它适合屏幕,四角的形状不好。 这是一个不使用自定义布局的对话框:

在此处输入图片说明

这是我的代码:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="7dp"
android:background="@android:color/white"
android:paddingRight="7dp"
android:paddingTop="20dp">

如果我不使用背景色,则对话框将没有背景色,并且将是透明的。

对于不使用自定义对话框的对话框,我使用以下样式:

<style name="MaterialDialogSheet" parent="@android:style/Theme.Dialog">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowAnimationStyle">@style/MaterialDialogSheetAnimation</item>
</style>

<style name="MaterialDialogSheetAnimation">
    <item name="android:windowEnterAnimation">@anim/popup_show</item>
    <item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>

如何使自定义对话框背景像未使用自定义布局的对话框一样?

有点晚了,但是这里是如何按照您的风格进行操作:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="alertDialogTheme">@style/myAlertDialogStyle</item>
</style>

<style name="myAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/Blue</item>
</style>

colorAccent将为对话框的输入着色。

暂无
暂无

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

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