Search code examples
androidandroid-layoutxamarin.androidandroid-softkeyboard

White background shows during 1 sec when keyboard closes on Android


When I tap to close the virtual keyboard, white background is shown on that place for 1 second.

I use Activity(WindowSoftInputMode = SoftInput.AdjustResize) to push “Done” button above the virtual keyboard but see a white background.

If I use Activity(WindowSoftInputMode = SoftInput.AdjustPan) there is no white background, but there is no "Done" button above.

How to fix a white background using AdjustResize?

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/itemsRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <Button
        android:id="@+id/doneButton"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:visibility="gone" />

</LinearLayout>

Theme:

  <style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">#f2f2f2</item>
    <item name="colorPrimaryDark">#f2f2f2</item>
    <item name="colorAccent">#f2f2f2</item>
    <item name="colorControlHighlight">@color/blue</item>

  </style>

  <style name="AppTheme" parent="AppTheme.Base">
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
    <item name="colorAccent">#979797</item>
  </style>

Solution

  • I solved the problem using the code below:

    FindViewById(Android.Resource.Id.Content).RootView.SetBackgroundColor(Color.Transparent);
    

    Edit 13-06-23:

    In your MainActivity.kt:

    window.decorView.rootView.setBackgroundColor(Color.TRANSPARENT);