CymChad / BaseRecyclerViewAdapterHelper

BRVAH:Powerful and flexible RecyclerAdapter
http://www.recyclerview.org/
MIT License
24.36k stars 5.17k forks source link

headview 要是有editview 会出现软键盘弹出又消失的情况 #3326

Open woaimi520 opened 4 years ago

woaimi520 commented 4 years ago

使用的3.0.4版本

问题现象:目前要做一个兑换优惠卷的功能 界面结构:activity中包含一个fragment ,fragment中包含recycleview 1 如果只添加headview 那么 headview中的editview一切正常 2 如果添加headview 同时添加了其他数据 那么点击 editview会看到 软键盘闪一下就消失

目前尝试了 在activitry 添加 android:windowSoftInputMode="stateHidden|adjustPan" 在recycleview中添加 android:descendantFocusability="beforeDescendants" 在editview中点击开启软键盘

以上都未解决问题

部分代码 添加的headview 如下 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="@dimen/dp_10">

<androidx.appcompat.widget.AppCompatEditText
    android:id="@+id/ed_phone"
    android:layout_width="0dp"
    android:layout_height="@dimen/dp_35"
    android:layout_marginEnd="@dimen/dp_10"
    android:background="@color/white_ffffff"
    android:gravity="center_vertical"
    android:hint="输入兑换码"
    android:maxLength="20"
    android:paddingLeft="@dimen/dp_12"
    android:paddingRight="@dimen/dp_12"
    android:textColor="@color/black3"
    android:textColorHint="@color/black9"
    android:textSize="@dimen/sp_15"
    android:backgroundTint="@color/white_ffffff"
    android:layout_marginStart="@dimen/dp_20"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    app:layout_constraintEnd_toStartOf="@+id/confirm_btn"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    />

<androidx.appcompat.widget.AppCompatButton
    android:id="@+id/confirm_btn"
    android:layout_width="@dimen/dp_55"
    android:layout_height="@dimen/dp_35"
    android:paddingStart="@dimen/dp_10"
    android:paddingEnd="@dimen/dp_10"
    android:paddingTop="@dimen/dp_5"
    android:paddingBottom="@dimen/dp_5"
    android:background="@drawable/all_selector_bt_orange"
    android:gravity="center"
    android:enabled="true"
    android:text="兑换"
    android:textColor="@color/white_ffffff"
    android:textSize="15sp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/ed_phone"
/>

</androidx.constraintlayout.widget.ConstraintLayout>

val headView = View.inflate(activity, R.layout.item_unuse_coupon_list_item_head, null)

    var btn = headView.findViewById<AppCompatButton>(R.id.confirm_btn)
    btn.setOnClickListener {
        var code =headView.findViewById<AppCompatEditText>(R.id.ed_phone).text
        if(TextUtils.isEmpty(code)){
            activity?.toast("请输入兑换码")
            return@setOnClickListener
        }

        viewModel.exchangeCouponS(code.toString())

    }
    var ediview =   headView.findViewById<AppCompatEditText>(R.id.ed_phone)
    ediview.setOnClickListener{
        context?.let {
            showSoftKeyboard(it,ediview)
        }

    }
    ediview.setOnFocusChangeListener{ v,hasFocus->

        hasFocus
    }

ar adapter = object : BaseQuickAdapter<GuoGuoCouponBean, BaseViewHolder>(R.layout.item_unuse_coupon_list_item) { override fun convert(helper: BaseViewHolder, item: GuoGuoCouponBean) {

            if("2" == item.couponType){
                //折扣卷
                var data :String?=null
                (item.rate?:10.00).let {
                    data = DigitalConversionUtils.convertDoubleToString( it)//保留一位有效数字并去掉末尾的0
                }
                data?.let {
                    var dataFormat = String.format(resources.getString(R.string.discount_yang),it) //拼接字符
                    val span: Spannable = SpannableString(dataFormat)
                    //注意这里的span 0.4是缩放比例 一定注意 RelativeSizeSpan 每次都要单独生成
                    span.setSpan( RelativeSizeSpan(0.4f), dataFormat.length-1, dataFormat.length-1, Spannable.SPAN_INCLUSIVE_INCLUSIVE)//(]

// span.setSpan(ForegroundColorSpan(Color.RED), dataFormat.length-1, dataFormat.length-1, Spannable.SPAN_INCLUSIVE_INCLUSIVE) helper.setText(R.id.discount,span) } }else{ var data :String?=null (item.amount?:0.01).let { data = DigitalConversionUtils.convertDoubleToString( it)//去掉末尾的0 } data?.let { var dataFormat = String.format(resources.getString(R.string.yang_discount),it) //拼接字符 val span: Spannable = SpannableString(dataFormat) span.setSpan( RelativeSizeSpan(0.4f), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE)//(] // span.setSpan( ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE) helper.setText(R.id.discount,span) }

            }

            helper.setText(R.id.title, item.couponName)
            helper.setText(
                R.id.subtitle,
                TimeFormateUtils.getHomeUpdateTime2(
                    item.startTime?.toLong() ?: 1
                ) + "至" + TimeFormateUtils.getHomeUpdateTime2(
                    item.endTime?.toLong() ?: 1
                )
            )
        }

    }
CordyHo commented 4 years ago

在recyclerview里加上 android:focusableInTouchMode="true" ,以及recyclerview的父布局都加上