仿抖音评论,弹出PopuWindow位于屏幕底端时EditText遮挡问题

我们都知道popuwind弹出时,如果popuwindow里面有edittext会使软件盘遮挡不弹出,需要设置如下代码。

//设置弹出窗体需要软键盘,
window.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
//再设置模式,和Activity的一样,覆盖。
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

我这里是低仿抖音,高仿腾讯微视做的,popuWindow的Edittext是位于屏幕底部的,弹出后会有一些遮挡

因为设置了Edittext的background为null

仿抖音评论,弹出PopuWindow位于屏幕底端时EditText遮挡问题_第1张图片

 

然后设置了Edittext的background为透明之后,成功变得好看了许多。

仿抖音评论,弹出PopuWindow位于屏幕底端时EditText遮挡问题_第2张图片

好,图片粘贴完毕,开始干货代码走起!!!

首先是Activity:

//弹出popuWindow
private void ShowPopuWindow(int height) {
    View contentView = LayoutInflater.from(this).inflate(R.layout.faxian_message_item, null, false);
    AutoUtils.auto(contentView);
    window = new PopupWindow(this);
    window.setContentView(contentView);
    window.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    //设置高度
    int screenHeigh = getResources().getDisplayMetrics().heightPixels;
    window.setHeight(Math.round(screenHeigh * 0.7f));
    window.setOutsideTouchable(true);
    window.setTouchable(true);
    window.setFocusable(true);
    //设置弹出窗体需要软键盘,
    window.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
    //再设置模式,和Activity的一样,覆盖。
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

    // 实例化一个ColorDrawable颜色为半透明
    ColorDrawable dw = new ColorDrawable(0xb0000000);
    // 设置弹出窗体的背景
    window.setBackgroundDrawable(dw);
    //window.update();
    window.setAnimationStyle(R.style.popwin_anim_style);
    window.showAtLocation(layout, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    //设置背景颜色
    RelativeLayout popu_layout = (RelativeLayout) contentView.findViewById(R.id.layout);
    popu_layout.setBackgroundColor(Color.argb(105,0,0,0));
    LinearLayout bottom_layout = (LinearLayout) contentView.findViewById(R.id.bottom_layout);
    RecyclerView recyclerView = (RecyclerView) contentView.findViewById(R.id.recycleView);
    LinearLayoutManager manager = new LinearLayoutManager(FaXianActivity.this, LinearLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(manager);
    adapter = new PopuwindowAdapter(FaXianActivity.this, list);
    recyclerView.setAdapter(adapter);
    initMessage();
    ImageView close = (ImageView) contentView.findViewById(R.id.image_close);
    close.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            window.dismiss();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);//开启或者关闭软键盘
            edit_text.setText("");
        }
    });
    edit_text = (EditText) contentView.findViewById(R.id.edit_message);
    commit = (TextView) contentView.findViewById(R.id.text_commit);
    commit1 = (TextView) contentView.findViewById(R.id.text_commit1);
    message_num = (TextView) contentView.findViewById(R.id.message_num);
    commit.setEnabled(false);
    commit1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) { 
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);//开启或者关闭软键盘
            edit_text.setText("");
        }
    });
    edit_text.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            String trim = s.toString().trim();
            if (!TextUtils.isEmpty(trim)) {
                //个人较懒,直接控件显示隐藏了
                commit.setVisibility(View.GONE);
                commit1.setVisibility(View.VISIBLE);
            } else {
                commit.setVisibility(View.VISIBLE);
                commit1.setVisibility(View.GONE);
            }
        }
    });
}

popuWindow的动画:

首先Style文件里写一个:

弹出动画menuShow:



    

关闭动画menuhide:



    

 

然后是popuWindow的布局:

?xml version="1.0" encoding="utf-8"?>



    

    


    

    

        

        

        
    


发送按钮的圆形边框:



    
    
    

重点来了!!!EditText的下划线,在Drwaable文件夹下创建:

这个是edit_end的xml:



    
    

这个是edit_select的xml:




    
        
            
            
            
        
    

最后贴一张效果图:

仿抖音评论,弹出PopuWindow位于屏幕底端时EditText遮挡问题_第3张图片

你可能感兴趣的:(仿抖音评论,弹出PopuWindow位于屏幕底端时EditText遮挡问题)