title: How to save soft-keyboard open when edittext is not focused
body: <p>I have an EditText and SwitchCompat inside the ScrollView. When the EditText recieve a focus, I want to show soft-keyboard, and when I touch the ScrollView keyboard should remain open.
  I use this code:</p>
  <pre><code>et_phone_input.setOnFocusChangeListener { view, b -&gt;
              if (b) {
                  setFocusAndShowKeyboard2(editText, requireContext())
              } 
          }
  
  fun setFocusAndShowKeyboard2(view : View, context: Context){
      view.requestFocus()
      val imm: InputMethodManager =
          ContextCompat.getSystemService(context, Context.INPUT_METHOD_SERVICE) as InputMethodManager
      imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
  }
  </code></pre>
  <p>It works good in API 27, but does not work for API 28, 29, 30.</p>
  <p>Even I use the <code>InputMethodManager.SHOW_FORSED</code>, when I swith the SwithCompat widget keyboard hides.
  I try to use     <code>imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)</code>, but there is anoter problem: when I leave a Fragment and show the Dialog - keyboard stay.
  Is that possible to fix it?</p>
  <p><strong>UPDATE</strong>: added xml layout file of the screen</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      android:background=&quot;@color/background&quot;
      android:layout_margin=&quot;@dimen/margin16&quot;&gt;
  
      &lt;ScrollView
          android:id=&quot;@+id/scroll_view&quot;
          android:layout_width=&quot;fill_parent&quot;
          android:layout_height=&quot;fill_parent&quot;
          android:orientation=&quot;vertical&quot;
          app:flow_verticalAlign=&quot;center&quot;
          android:scrollbars=&quot;none&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          android:fillViewport=&quot;true&quot;&gt;
  
          &lt;androidx.constraintlayout.widget.ConstraintLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;match_parent&quot;&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/textView&quot;
                  style=&quot;@style/TextMainHeader&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;20dp&quot;
                  android:text=&quot;@string/login_header&quot;
                  app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
              &lt;androidx.recyclerview.widget.RecyclerView
                  android:id=&quot;@+id/rv_agreement_points&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toBottomOf=&quot;@+id/textView&quot;
                  android:layout_marginTop=&quot;@dimen/margin4&quot;/&gt;
  
  
              &lt;TextView
                  android:id=&quot;@+id/header_your_phone&quot;
                  style=&quot;@style/TextMainHeader&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;40dp&quot;
                  android:text=&quot;@string/header_your_phone&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toBottomOf=&quot;@+id/rv_agreement_points&quot; /&gt;
  
              &lt;EditText
                  android:id=&quot;@+id/et_phone_input&quot;
                  style=&quot;@style/TextPhone&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;@dimen/margin8&quot;
                  android:background=&quot;@drawable/rounded_corners_r8&quot;
                  android:backgroundTint=&quot;@color/input_inactive&quot;
                  android:inputType=&quot;phone&quot;
                  android:singleLine=&quot;true&quot;
                  android:maxLines=&quot;1&quot;
                  android:text=&quot;+7&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toBottomOf=&quot;@+id/header_your_phone&quot;/&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/phone_error&quot;
                  style=&quot;@style/TextSmallError&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;@dimen/margin4&quot;
                  android:text=&quot;Номер должен начинаться на +79 или +77&quot;
                  android:visibility=&quot;gone&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toBottomOf=&quot;@+id/et_phone_input&quot; /&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/links&quot;
                  style=&quot;@style/TextTertiary&quot;
                  android:layout_width=&quot;0dp&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;30dp&quot;
                  android:layout_marginEnd=&quot;@dimen/margin16&quot;
                  android:textColorLink=&quot;@color/brand&quot;
                  android:text=&quot;Я соглашаюсь на обработку персональных данных, с политикой конфиденциальности и условиями сервиса &quot;
                  app:layout_constraintEnd_toStartOf=&quot;@+id/switch_agreement&quot;
                  app:layout_constraintHorizontal_bias=&quot;0.5&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toBottomOf=&quot;@+id/et_phone_input&quot;
                  app:layout_constraintWidth_percent=&quot;0.73&quot; /&gt;
  
              &lt;TextView
                  android:id=&quot;@+id/empty_space&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;70dp&quot;
                  app:layout_constraintTop_toBottomOf=&quot;@+id/links&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;/&gt;
  
  
              &lt;androidx.appcompat.widget.SwitchCompat
                  android:id=&quot;@+id/switch_agreement&quot;
                  style=&quot;@style/MySwitch&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_alignParentRight=&quot;true&quot;
                  android:layout_marginEnd=&quot;11dp&quot;
                  android:checked=&quot;false&quot;
                  android:minHeight=&quot;48dp&quot;
                  app:layout_constraintBottom_toBottomOf=&quot;@id/links&quot;
                  app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                  app:layout_constraintHorizontal_bias=&quot;0.5&quot;
                  app:layout_constraintStart_toEndOf=&quot;@+id/links&quot;
                  app:layout_constraintTop_toTopOf=&quot;@+id/links&quot; /&gt;
  
  
          &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
      &lt;/ScrollView&gt;
  
      &lt;LinearLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          android:background=&quot;@color/background&quot;&gt;
  
  
          &lt;Button
              android:id=&quot;@+id/button_take_code&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:text=&quot;@string/take_code&quot;
              style=&quot;@style/MyButton&quot;/&gt;
  
      &lt;/LinearLayout&gt;
      
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>and part of Fragment code. According to the designer's idea, if the user clicks on the input, the screenView scrolls up. Maybe, problem is there.</p>
  <pre><code>input.setOnFocusChangeListener { view, b -&gt;
      if (b) {
          setFocusAndShowKeyboard2(input, requireContext())
          isInputClicked.postValue(true)
          input.setBackgroundTintList(
              ContextCompat.getColorStateList(
                  requireContext(),
                  R.color.input_active
              )
          )
      } 
  }
  
  isInputClicked.observe(viewLifecycleOwner, Observer {
      if (it) {
          var errorTimer = object: CountDownTimer(50L, 10L) {
              override fun onTick(millisUntilFinished: Long) {
                  if (millisUntilFinished &lt; 400L) {
                  }
              }
              override fun onFinish() {
                  scrollView.postDelayed(Runnable() {
                      run() {
                          scrollView.fullScroll(ScrollView.FOCUS_DOWN)
                      }
                  }, 200)
              }
          }.start()
  
      }
  })
  </code></pre>