码迷,mamicode.com
首页 > 移动开发 > 详细

Android 弹出对话框Dialog充满屏幕宽度

时间:2016-08-09 00:00:56      阅读:411      评论:0      收藏:0      [点我收藏+]

标签:

        final View view = LayoutInflater.from(context).inflate(layoutId, null);

        final Dialog dialog = new Dialog(context, R.style.style_dialog);
        dialog.setContentView(view);
        dialog.show();

        Window window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.dialog_animation);
        window.getDecorView().setPadding(0, 0, 0, 0);

        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);

 style_dialog:

<style name="style_dialog" parent="android:style/Theme.Dialog">
    <item name="android:windowBackground">@color/white</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:scrollHorizontally">true</item>
    </style>

 

dialog_animation:

    <style name="dialog_animation">  
        <item name="android:windowEnterAnimation">@anim/enter</item>   
     <item name="android:windowExitAnimation">@anim/exit</item>   
    </style>

enter:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    
    <translate 
        android:fromYDelta="100%p"
        android:toYDelta="0"
        android:duration="300"
        />

</set>

exit:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >
    
    <translate 
        android:fromYDelta="0"
        android:toYDelta="100%p"
        android:duration="600"
        />

</set>

 

Android 弹出对话框Dialog充满屏幕宽度

标签:

原文地址:http://www.cnblogs.com/anni-qianqian/p/5751331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!