简单的底部弹出窗,BottomSheetDialog

1 BottomSheetDialog 底部弹出框

BottomSheetDialog的简单使用:

 /**
     * func:弹出举报dialog
     */
    private void showShieldDialog(long articleId,int articleType) {
            if (getActivity() == null) return;
            if (sheildDialog != null && sheildDialog.isShowing()) {
                sheildDialog.dismiss();
            }
            sheildDialog = new BottomSheetDialog(getActivity(), R.style.BottomSheetEdit);
            View tCommentView = LayoutInflater.from(getActivity()).inflate(R.layout.community_sheild_layout, null);
            final TextView notSeeDynamic = tCommentView.findViewById(R.id.bottom_view_not_see_dynamic);
            final TextView notSeeUser = tCommentView.findViewById(R.id.bottom_view_not_see_user);
            final TextView shield = tCommentView.findViewById(R.id.bottom_view_shield);
            final TextView cancle = tCommentView.findViewById(R.id.bottom_view_cancle);
            sheildDialog.setContentView(tCommentView);
            cancle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    sheildDialog.dismiss();
                }
            });

             notSeeDynamic.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    sheildDialog.dismiss();
                  
                }
            });

            notSeeUser.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    sheildDialog.dismiss();
                   
                }
            });

          shield.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sheildDialog.dismiss();
               
            }
           });
            sheildDialog.show();
    }
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:id="@+id/bottom_view_not_see_dynamic"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="不再查看此条动态"
        android:textSize="18sp"
        android:textColor="#FF000000"
        android:gravity="center"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#FFF2F2F2">
    </View>
    <TextView
        android:id="@+id/bottom_view_not_see_user"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="不再查看此人动态"
        android:textSize="18sp"
        android:textColor="#FF000000"
        android:gravity="center"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#FFF2F2F2">
    </View>

    <TextView
        android:id="@+id/bottom_view_shield"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="投诉"
        android:textSize="18sp"
        android:textColor="#FF000000"
        android:gravity="center"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="6dp"
        android:background="#FFF2F2F2">
    </View>

    <TextView
        android:id="@+id/bottom_view_cancle"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="取消"
        android:textSize="18sp"
        android:textColor="#FF000000"
        android:gravity="center"/>

</LinearLayout>
//style
 <style name="BottomSheetEdit" parent="Theme.Design.Light.BottomSheetDialog">
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowSoftInputMode">adjustResize</item>
    </style>

在这里插入图片描述

2 键盘遮挡问题

BottomSheetDialog中存在一个editText时,当软键盘出现后,键盘会覆盖焦点以下的dialog,

  private void showCommentDialog2() {
        BottomSheetDialog  dialog2 = new BottomSheetDialog(this);
        View commentView = LayoutInflater.from(this).inflate(R.layout.select_car_keyboard2, null);

        dialog2.setContentView(commentView);
        dialog2.show();
    }

在这里插入图片描述
在这里插入图片描述
解决可以利用ajustResize会重新布局当前窗口,且需要当前dialog不是浮动的。
解决方案:为创建的bottomSheetDialog设置自定style,代码如下

<style name="BottomSheetEdit" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="android:windowIsFloating">false</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowSoftInputMode">adjustResize</item>
</style>
   bottomSheetDialog = new BottomSheetDialog(this, R.style.BottomSheetEdit);

解决代码:

  private void showCommentDialog2() {
        BottomSheetDialog  dialog2 = new BottomSheetDialog(this, R.style.BottomSheetEdit);
     //   BottomSheetDialog  dialog2 = new BottomSheetDialog(this);
        View commentView = LayoutInflater.from(this).inflate(R.layout.select_car_keyboard2, null);

        dialog2.setContentView(commentView);
        dialog2.show();
    }

在这里插入图片描述
特别注意:其实我们仔细 观察,还是可以发现BottomSheetDialog设置了style后,底部依然会被遮挡。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值