自定义底部弹出Dialog//仿输入法

    // 实现点击

public class MyDialog extends Dialog implements View.OnClickListener

//  自定义style ,    底部显示 弹出

 public DesDialog(Context context) {
        super(context, R.style.MyDialogStyle);
    }


 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置对话框的布局 用法跟activity没有区别
        setContentView(R.layout.layout_desdialog);
        ButterKnife.bind(this);

//1 获取window
        Window window = getWindow();
//2 获取布局参数
        WindowManager.LayoutParams layoutParams = window.getAttributes();
//3 修改gravity 让窗口靠着父容器的底部
        layoutParams.gravity = Gravity.BOTTOM;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.getDecorView().setPadding(0,0,0,0);
//4 把修改好的布局参数 设置到窗口中
        window.setAttributes(layoutParams);
    }

// style

 <style name="MyDialogStyle" parent="@style/Theme.AppCompat.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:windowAnimationStyle">@style/customerAnimation</item>
    </style>
  <style name="customerAnimation">
        <item name="android:windowEnterAnimation">@anim/dialog_enter</item>
        <item name="android:windowExitAnimation">@anim/dialog_exit</item>
    </style>
//res下 anim文件夹
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="200"
        android:toYDelta="0%"
        android:fillAfter="true"
        android:fromYDelta="100%p" />
</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="200"
        android:fromYDelta="0%"
        android:fillAfter="true"
        android:toYDelta="100%p" />
</set>
//res下 anim enter &exit
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="200"
        android:toYDelta="0%"
        android:fillAfter="true"
        android:fromYDelta="100%p" />
</set>


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



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值