junixapp / XPopup

🔥XPopup2.0版本重磅来袭,2倍以上性能提升,带来可观的动画性能优化和交互细节的提升!!!功能强大,交互优雅,动画丝滑的通用弹窗!可以替代Dialog,PopupWindow,PopupMenu,BottomSheet,DrawerLayout,Spinner等组件,自带十几种效果良好的动画, 支持完全的UI和动画自定义!(Powerful and Beautiful Popup for Android,can absolutely replace Dialog,PopupWindow,PopupMenu,BottomSheet,DrawerLayout,Spinner. With built-in animators , very easy to custom popup view.)
Apache License 2.0
7.76k stars 1.17k forks source link

带输入框的对话框,怎么让软键盘一起弹出来 #41

Closed Blizzard-liu closed 5 years ago

junixapp commented 5 years ago

@Blizzard-liu 你是说在弹窗显示的同时让软键盘弹出来,那你完全可以在show之后让软键盘显示出来。

Blizzard-liu commented 5 years ago

我试下

Blizzard-liu commented 5 years ago

` edit_text.isFocusable = true edit_text.isFocusableInTouchMode = true edit_text.requestFocus() InputMethodUtils.showInputMethod(edit_text,100)

只能在dialog内唤起,外面不行

junixapp commented 5 years ago

@Blizzard-liu 在你弹出弹窗后点击输入框不就能弹出输入法了吗,你的需求是什么样的?

Blizzard-liu commented 5 years ago

继承BottomPopupView,当软键盘弹出后,点击外部空白区域不消失,隐藏软键盘就没有问题了

edit_text是获取焦点的

Blizzard-liu commented 5 years ago

''' class CommentPopup(val context: Activity,val title: String,val hint: String,val listener: OnSubmitClickListener) : BottomPopupView(context) { override fun getImplLayoutId(): Int { return R.layout.dialog_resume_layout }

override fun initPopupContent() {
    super.initPopupContent()
    iv_close.setOnClickListener {
        dismiss()
    }

    tv_title.text = title
    edit_text.hint = hint
    if (title.contains("留言")) {
        //简历/面试结果必选,备注内容选填(最多200字)
        //只有选中面试结果后,提交按钮才可用
        recyclerView.visibility = View.GONE
        btn_submit.isEnabled  = false
    }

    recyclerView.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL,false)
    recyclerView.addItemDecoration(CommonItemDecoration(20,0))
    val data = arrayListOf<ResumeDialogBean>().apply {
        add(ResumeDialogBean("优秀",true))
        add(ResumeDialogBean("良好"))
        add(ResumeDialogBean("合格"))
        add(ResumeDialogBean("不合格"))
    }
    val adapter =  ResumeBottomAdapter(context,data)
    recyclerView.adapter = adapter
    adapter.setOnItemClickListener { _adapter, _, position ->
        data.forEach {
            it.isChecked = false
        }
        val bean = _adapter.data[position] as ResumeDialogBean
        bean.isChecked = true
        _adapter.notifyDataSetChanged()

    }

    edit_text.filters = arrayOf<InputFilter>(InputFilter { source, _, _, dest, _, _ ->
        if (dest.toString().length + source.length <= 200) {
            return@InputFilter source //匹配 source为新字符  dest为原字符
        } else {
            if (dest.toString().length >= 200) {
                ToastUtils.Infotoast(context,"最多只能输入200个文字")
                "" //返回""
            } else {
                source.subSequence(0, 200 - dest.toString().length)
            }
        }
    })

    edit_text.addTextChangedListener(object : TextWatcher {

        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
        }

        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int,
                                       after: Int) {
        }

        override fun afterTextChanged(s: Editable) {
            // 输入后的监听
            btn_submit.isEnabled = !(TextUtils.isEmpty(s.toString()) && title.contains("留言"))

        }
    })

    btn_submit.setOnClickListener {
        var label = ""
        if (!title.contains("留言")) {
            data.forEach { item ->
                if (item.isChecked) {
                    label = item.title
                    return@forEach
                }
            }
        }
        listener.onSubmit(label,edit_text.text.toString())
        dismiss()
    }
    Utils.showSoftInput(context,edit_text)
}

interface OnSubmitClickListener {
    fun onSubmit(label: String,msg: String)
}

'''

junixapp commented 5 years ago

@Blizzard-liu 刚才试了下确实有这个bug,我抽空修复下。

Blizzard-liu commented 5 years ago

ok

Blizzard-liu commented 5 years ago

大佬 可以试下kotlin

junixapp commented 5 years ago

@Blizzard-liu 如果你用Kotlin,千万不要错过我的另一个库: https://github.com/li-xiaojun/AndroidKTX 让你爽翻天。

Blizzard-liu commented 5 years ago

牛逼牛逼

junixapp commented 5 years ago

@Blizzard-liu 点击外部无法消失的Bug在最新版本1.3.8已经解决,请更新试试。

Blizzard-liu commented 5 years ago

image

这个提示怎么去掉 看着好烦

junixapp commented 5 years ago

@Blizzard-liu 相信我不要去掉它,它会在你的代码出问题时才提示,有时候能帮上很大忙。

Blizzard-liu commented 5 years ago

我实说这个类名报黄,正常应该没有才对

Blizzard-liu commented 5 years ago

1.3.8问题更严重了 软键盘和对话框之间有空白,而且空白距离不固定

Blizzard-liu commented 5 years ago

软键盘收起在弹出,又会盖住dialog

junixapp commented 5 years ago

@Blizzard-liu 可以加我QQ: 16167479 把出问题的代码发我一份,我帮你看看。我这边不好复现

junixapp commented 5 years ago

@Blizzard-liu 在最新版本1.3.9增加了autoOpenSoftInput的设置,只需执行如下设置:

XPopup.get(this).autoOpenSoftInput(true) //是否弹窗显示的同时打开输入法,只在包含输入框的弹窗内才有效,默认为false

无需再自己操作输入法。

ZakAnun commented 5 years ago

@li-xiaojun 大佬,想问下有监听软件关闭的回调吗?我在软键盘弹出后点击软键盘的关闭按钮,弹窗没有关闭,请问可以在哪里将弹框关闭?