4

i have use Edittext in ViewPager>Fragment>NestedScrollView>RecyclerView>Edittext

when i show/hide keyboard it take too many time to show/hide and also show me white background. i all things use like AdjustResize,AdjustPan

enter image description here

after close keyboard show white background like bellow

enter image description here

please help me for resolve this issues

Adil Saiyad
  • 1,582
  • 2
  • 17
  • 34

4 Answers4

2

I think this performance issue is due to complex hierarchy of your screen. Try to set android:windowSoftInputMode="adjustNothing".

If glitch will gone try to simplify hierarchy

For example in ViewPager>Fragment>NestedScrollView>RecyclerView>Edittext

Remove NestedScrollView (reuse RecyclerView behaviour or use Airbnb Epoxy library)

PS: also check what application not perform heavy tasks when you focus this field

Peter Staranchuk
  • 1,343
  • 3
  • 14
  • 29
0

Hide soft keyboard. @param callingActivity the calling activity

 fun hideSoftKeyboard(callingActivity: Activity) {
        if (callingActivity.currentFocus != null) {
            val inputManager = callingActivity
                    .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            inputManager.hideSoftInputFromWindow(callingActivity
                    .currentFocus!!.windowToken,
                    InputMethodManager.HIDE_NOT_ALWAYS)
        }
    }
RanaUmer
  • 561
  • 5
  • 9
0

For hide soft keyboard

fun hideKeyboard(view: View?) {
        if (view != null) {
            val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.hideSoftInputFromWindow(view.windowToken, 0)
        }
    }

for show soft keyboard

fun showKeyboard(activity: Activity, editText: View) {
        val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
    }
Ashish
  • 116
  • 4
0

Without looking into your code, it's hard to say what could be causing the performance issue. But I see you display image in view pager. Creating bitmap is CPU and memory intensive task. I guess when you open the ViewPager, the keyboard opens up at the same time as creating bitmap. Try to disable the keyboard on first activity start. Only start when EditText gains focus and also try to cache created Bitmaps to some extent to save some CPU cycles. Here is the official guide for this.. While loading bitmaps, we also need to care the size of the Bitmap we are loading in memory as compared to the ImageView size. If we load large bitmap than the ImageView's bound, definitely it is waste of resources. See Loading Large Bitmaps Efficiently. It is always advisable to use any image loading library to do all the heavy lifting. Here is one such library I've been using Glide

For leaving the white background, check the ViewPager height is match-parent or match-constraint. I also had a problem similar to this in RecyclerView, I solved this as mentioned here RecyclerView drawing offscreen

 val obs = pager?.viewTreeObserver
           obs?.addOnGlobalLayoutListener {
                    recyclerView?.requestLayout()
                    recyclerView?.invalidate()
           }
Hitesh Gupta
  • 1,091
  • 9
  • 14