如何在Android的警报对话框中添加阴影效果 [英] how to add shadow effect in alert dialog box in android

查看:91
本文介绍了如何在Android的警报对话框中添加阴影效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在警报对话框中添加阴影效果.我希望在对话框中使用这种阴影效果在这里,我发布了3个文件,第一个是style.xml,第二个是theme.java或第三个文件是demo_bg.xml文件.我已经尝试过了

i want to add shadow effect in alert dialog box . i want this type of shadow effect in my dialog box here i post 3 files first is style.xml second is theme.java or third file is demo_bg.xml file.i already try like that

Style.xml 
 <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorAccent">@color/bg_color</item>
        <item name="android:textColorPrimary">@color/colorBlack</item>
        <item name="android:background">@drawable/demo_bg</item>

    </style>

theme.java

final AlertDialog.Builder builder =
                new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
        builder.setMessage(R.string.wsdialogdata);
        builder.setPositiveButton("START", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent ii = new Intent(WelcomeFromActivity.this, Question1Activity.class);
                startActivity(ii);
            }
        });
        builder.show();



demo_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <!-- SHADOW LAYER -->
            <item android:left="2dp" android:top="2dp">
                <shape>
                    <solid android:color="#66000000" />
                    <corners android:radius="35dip" />
                </shape>
            </item>
            <!-- CONTENT LAYER -->
            <item android:bottom="4dp" android:right="4dp">
                <shape>
                    <solid android:color="@color/btn_fb" />
                    <corners android:radius="40dip" />
                </shape>
            </item>
        </layer-list>
    </item>
</selector>

推荐答案

创建background_shadow.xml

create background_shadow.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#50CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#10CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#20CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#30CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:bottom="1dp" />
            <solid android:color="#50CCCCCC" />
        </shape>
    </item>

    <item>
        <shape>
            <padding android:right="1dp" />
            <solid android:color="#50CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:right="1dp" />
            <solid android:color="#10CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:right="1dp" />
            <solid android:color="#20CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:right="1dp" />
            <solid android:color="#30CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <padding android:right="1dp" />
            <solid android:color="#50CCCCCC" />
        </shape>
    </item>
    <item>
        <shape>
            <solid android:color="@color/white" />
        </shape>
    </item>
</layer-list>

样式

 <style name="AppCompatAlertDialogStyle" parent="android:Theme.Dialog">
        <item name="android:windowBackground">@drawable/background_shadow</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>

显示对话框

Dialog dialog = new Dialog(mContext, R.style.AppCompatAlertDialogStyle);
builderSingle.setTitle(getString(R.string.select_quantity));
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.layout);
dialog.show();

希望这可以解决您的问题

Hope this will solve your problem

这篇关于如何在Android的警报对话框中添加阴影效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆