底部弹框

private Dialog dialog;

if (dialog == null) {
            dialog = new Dialog(getActivity(), R.style.ActionSheetDialogStyle);
            //填充对话框的布局
            View inflate = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_pick, null);
            RecyclerView mRecyclerView = (RecyclerView) inflate.findViewById(R.id.rv_dialog_pick);
            mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
            TextView tvDelete = (TextView) inflate.findViewById(R.id.tv_pick_tittle);
            tvDelete.setText(R.string.call_record_dlg_delete);
            tvDelete.setTextColor(ArmsUtils.getColor(getActivity(),R.color.text_color_red));
            tvDelete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    doDelete();
                }
            });


            //将布局设置给Dialog
            dialog.setContentView(inflate);
            //获取当前Activity所在的窗体
            Window dialogWindow = dialog.getWindow();
            //设置Dialog从窗体底部弹出
            dialogWindow.setGravity(Gravity.BOTTOM);
            //获得窗体的属性
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            //设置Dialog距离底部的距离
            lp.y = SizeUtils.dp2px(20);
            // 将属性设置给窗体
            dialogWindow.setAttributes(lp);

            inflate.findViewById(R.id.tv_pick_cancel).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
        }

        dialog.show();//显示对话框

样式:

  <!--选择器样式-->
    <style name="ActionSheetDialogStyle" parent="@android:style/Theme.Dialog">

        <!-- 背景透明 -->
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <!-- 浮于Activity之上 -->
        <item name="android:windowIsFloating">true</item>
        <!-- 边框 -->
        <item name="android:windowFrame">@null</item>
        <!-- Dialog以外的区域模糊效果 -->
        <item name="android:backgroundDimEnabled">true</item>
        <!-- 无标题 -->
        <item name="android:windowNoTitle">true</item>
        <!-- 半透明 -->
        <item name="android:windowIsTranslucent">true</item>
        <!-- Dialog进入及退出动画 -->
        <item name="android:windowAnimationStyle">@style/ActionSheetDialogAnimation</item>

        <item name="android:listPreferredItemPaddingLeft">4dip</item>
        <item name="android:listPreferredItemPaddingRight">4dip</item>

    </style>
    <!-- ActionSheet进出动画 -->
    <style name="ActionSheetDialogAnimation" parent="@android:style/Animation.Dialog">
        <item name="android:windowEnterAnimation">@anim/translate_up</item>
        <item name="android:windowExitAnimation">@anim/translate_down</item>
    </style>

布局:dialog_pick

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="300dp"
    android:orientation="vertical"

    >
    <!--
    android:layout_marginLeft="@dimen/sh_margin_left"
    android:layout_marginRight="@dimen/sh_margin_right"
    android:layout_marginTop="@dimen/sh_margin_top"

    -->

    <TextView
        android:id="@+id/tv_pick_tittle"
        android:layout_width="match_parent"
        android:layout_height="@dimen/item_height_main"
        android:layout_margin="2dp"
        android:background="@drawable/shape_white_rad15"
        android:gravity="center"
        android:text="请选择小V"
        android:textColor="@color/text_color_main"
        android:textSize="@dimen/text_size_main"
        android:visibility="visible" />


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_dialog_pick"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shape_white_rad15"

        ></android.support.v7.widget.RecyclerView>

    <TextView
        android:id="@+id/tv_pick_cancel"
        android:layout_width="match_parent"
        android:layout_height="@dimen/item_height_main"
        android:layout_marginTop="@dimen/sh_margin_top"
        android:background="@drawable/shape_white_rad15"
        android:gravity="center"
        android:text="取  消"
        android:textColor="@color/text_color_main_3"
        android:textSize="18sp" />
</LinearLayout>




阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页