Canberk Ozcelik
Canberk Ozcelik

Reputation: 641

Background glitch on keyboard closure

I'm facing a situation with a little complex fragment layout xml of mine,

So the hierarchy follows as:

RelativeLayout (no background)
--ScrollView (fillViewPort=true, scrollbars=none)
----FrameLayout (no background)
------LinearLayout (no background)
--------RelativeLayout (background color of gray)
----------EditText
...

So when the edittext clicked it opens soft keyboard (as expected), and when back press or some click block which hides keyboard with following method:

try {
        InputMethodManager inputMethodManager = (InputMethodManager) GlobalApplication.getInstance().getCurrentActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(GlobalApplication.getInstance().getCurrentActivity().getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {
        if (e.getMessage() != null)
            Log.d("KeyboardError", e.getMessage());
    }

The problem is I've a red background for the activity and when the hiding keyboard action happens, I'm seeing the activity's background instead of the gray background of the RelativeLayout, and it's happening like a glitch or stuck. After awhile it comes back to normal and shows proper background.

Thanks for help, cheers.

Upvotes: 3

Views: 1058

Answers (1)

Alican Temel
Alican Temel

Reputation: 1318

Use this in your base activity onCreate() after super.onCreate(savedInstanceState);

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

or

Add these lines in your manifest under your activity tag

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:windowSoftInputMode="stateHidden|adjustPan"

Upvotes: 3

Related Questions