Android 为对话框创建阴影
我想为我的自定义对话框创建一个阴影,这可能吗Android 为对话框创建阴影,android,android-layout,android-ui,Android,Android Layout,Android Ui,我想为我的自定义对话框创建一个阴影,这可能吗 GhazalActivity.public void viewShareMenu() { Dialog share=new Dialog(this,R.style.shareDialogStyle); share.setContentView(R.layout.share_popup_layout); LayoutParams params = share.getWindow().getAttribut
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:
<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>
@彩色/透明
真的
真的
1500
@颜色/温度
0
5.
10
假的
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>
有什么解决办法吗?试试这个,创建一个xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#ffffff"
android:centerColor="#d3d7cf"
android:endColor="#2e3436"
android:angle="90" />
</shape>
创建一个视图并将上面的xml设置为其背景,如:
<View android:id="@+id/divider" android:background="@drawable/black_white_gradient"
android:layout_width="match_parent" android:layout_height="5sp"
<!--greater the height, more wider the shadow-->
/>
我已经创建了自己的自定义对话框,其中有一个阴影,您可以根据需要使用它,第一步您应该为阴影和对话框框架创建一个Android形状。以下是我提供的(dialog\u frame\u 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>
<style name="my_dialog_theme">
...
<item name="android:windowBackground">@drawable/dialog_frame_shadow</item>
...
</style>
Dialog dialog = new Dialog(this, R.style.my_dialog_theme);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.mdialog);
dialog.show();