Is it possible to always show the action bar when using adjustPan as soft input mode?
Asked Answered
B

2

18

In my application I have a ListView with a footer that contains a custom view with an EditText inside. At the top sits an action bar. The activity currently uses SOFT_INPUT_ADJUST_RESIZE (adjustResize) as soft input mode and does not close the keyboard when scrolling.

To show more of the list I wanted to remove the keyboard when scrolling and to get a smoother scrolling behavior I want to change so that SOFT_INPUT_ADJUST_PAN (adjustPan) is used. However, if I change to adjustPan, the whole view, including the action bar, is pushed up. I'd like the list view to be pushed but the action bar stay at the top at all times. Is that possible to do? If not, is it possible to use adjustResize and get a smooth resize animation?

So far I have tried:

  • Requesting Window.FEATURE_ACTION_BAR_OVERLAY, but that did not help although the documentation sounded promising.
  • Moving around the action bar container depending on if the soft keyboard is visible or not, which ended up looking like a massively unstable hack so I scrapped it.
  • So far I have ruled out adjustResize, due to the drawing behavior that happens when scrolling, minimizing the keyboard and resizing the listview at the same time. Is there a way to make a smooth animated resize?
Blossom answered 8/3, 2013 at 14:59 Comment(4)
have you got it done? i have similar issueLamebrain
@Blossom I'm facing the same issue. Can you please update which approach you carried out to solve this issue?Ballou
@Ballou Unfortunately I did not solve it the way I wanted to (with adjustPan). I stuck with Plan B (adjustResize) and the platform I was working on tweaked its keyboard animations so that the result was acceptableBlossom
@Blossom Can you give a bit more details please. I'm also looking for smoother animation.Ballou
E
0

for adjustPan

put below code in your activity declaration line in manifest.xml file

android:windowSoftInputMode="adjustPan"

like

<activity
        android:name="activity"
        android:windowSoftInputMode="adjustPan" >
</activity>

for remove keybord while scrall

while you get result at that time execute below code

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

by this way you can remove keybord from screen.

Eade answered 17/4, 2015 at 8:46 Comment(1)
I think this answer doesn't solve the issue in the question hereGoines
F
0

So you can setup an OnTouchListener on the entire activity except the EditText. The best place to this would be BaseActivity. You can write a function like this:

private fun setupFocusOutside(view: View) {
    if (view !is EditText) {
        view.setOnTouchListener { _, _ ->
            hideKeyboard()
            false
        }
    }
 }
//Hides the Keyboard when the User clicks on the screen
fun hideKeyboard() {
    val currentView = this.currentFocus
    if (currentView != null) {
        currentView.clearFocus()
        val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.hideSoftInputFromWindow(currentView.windowToken, 0)
    }
}

You can then call the function like this inside the onCreate() of BaseActivity:

setupFocusOutside(findViewById(android.R.id.content))

Now whenever you tap/touch/swipe an area inside an activity which is not an edit text, the keyboard will be closed.

Fear answered 1/4, 2022 at 6:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.