创建阴影对话框 [英] Create shadow for dialog

查看:491
本文介绍了创建阴影对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个影子为我定制对话框可能?

I want to create a shadow for my custom dialog is that possible ?

GhazalActivity.public void viewShareMenu() {
        Dialog share=new Dialog(this,R.style.shareDialogStyle);
        share.setContentView(R.layout.share_popup_layout);
        LayoutParams params = share.getWindow().getAttributes();
        params.y = this.getResources().getDimensionPixelSize(R.dimen.topbar_height);
        params.gravity=(Gravity.RIGHT|Gravity.TOP);
        share.getWindow().setAttributes(params);
        share.show();
}

styles.xml:

styles.xml :

<style name="shareDialogStyle" parent="android:style/Theme.Dialog">
    <item name="android:windowBackground">@color/transparent</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:fadeEnabled">true</item>
    <item name="android:fadeDuration">1500</item>
    <item name="android:shadowColor">@color/temp</item>
    <item name="android:shadowDx">0</item>
    <item name="android:shadowDy">5</item>
    <item name="android:shadowRadius">10</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

share_popup_layout.xml:

share_popup_layout.xml :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="150dip"
    android:background="@color/bg_Ghazal_share_menu"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="right"
        style="@style/shareDialogButtons"/>
</LinearLayout>

有没有这样做,任何解决办法?

is there any solution for doing that ?

推荐答案

我已经创建了自己的自定义对话框有一个下降的阴影,您可以使用它作为你的愿望,在第一步中,你应该为阴影创建的Andr​​oid形和对话框架。这是我所提供的( dialog_frame_shadow.xml ):

I have created my own custom dialog with a dropped shadow, you can use it as your desire, in the first step you should create a Android shape for both shadow and dialog frame. Here is what I have supplied(dialog_frame_shadow.xml):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle"> <!-- this shape is used as shadow -->
            <padding android:bottom="5dp"
                android:left="5dp"
                android:right="5dp"
                android:top="5dp"/>
            <solid android:color="#44000000"/>
            <corners android:radius="5dp"/>
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle"> <!-- this is for dialog frame -->
            <corners android:radius="5dp"/>
            <stroke android:color="#ff272727" android:width="2dp" />
            <gradient android:angle="90"
                android:startColor="#ffa7a7a7"
                android:centerColor="#ff6a6a6a"
                android:endColor="#ffa7a7a7"
                android:type="linear"/>
        </shape>
    </item>
</layer-list>

在接下来的步骤,你应该改变你的对话主题,什么是以下内容:

In the next step you should change your dialog theme as what is in the following:

 <style name="my_dialog_theme">
     ...
     <item name="android:windowBackground">@drawable/dialog_frame_shadow</item>
     ...
 </style>

现在你正在做的,只是创建对话框类的新实例,并应用这一主题,以它(在对话框的构造函数):

Now you are done, Just create a new instance of the Dialog class and apply this theme to it(in Dialog constructor):

Dialog dialog = new Dialog(this, R.style.my_dialog_theme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.mdialog);
dialog.show();

下面是它的截图:

享受:)

Here is it's screenshot:

enjoy :)

这篇关于创建阴影对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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