ScrollView Not working when keyboard is showing in android

后端 未结 4 983
长发绾君心
长发绾君心 2020-12-19 11:00

My problem is when keyboard is open scrollview is not working. Means basically when I have Theme android:theme=\"@android:style/Theme.Black.NoTitleBar.Fullscreen\"

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 11:51

    I got the same problem. The fullcreen mode prevents the scrolling.

    In concrete, I tested several FLAGS and LAYOUTS. These are working and don't prevent scrolling:

    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    View.SYSTEM_UI_FLAG_FULLSCREEN
    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    

    These are preventing the scrolling and do not work:

    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
    

    So I got a workaround finally, took me some days, but it works!

    1. Choose a theme, that is not fullscreen in manifest.xml, e.g.:

      android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
      
    2. Add this code, that makes your activity fullscreen

      private static View systemUIView;
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          super.setContentView(R.layout.rootlayout); //your layout with the scrollview
      
          // hide the native android navigation and status bar
          systemUIView = getWindow().getDecorView();
          hideSystemUI();
      
          if (android.os.Build.VERSION.SDK_INT >= 19) {
              getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
                      new OnSystemUiVisibilityChangeListener() {
                          @Override
                          public void onSystemUiVisibilityChange(int visibility) {
                              if (visibility == 0) {
                                  hideSystemUI();
                              }
                          }
                      });
          }
      
      // ... here comes my whole code...      
      }
      
      @Override
      public void onResume() {
          super.onResume();
          hideSystemUI();
      }
      
      public void hideSystemUI() {
          systemUIView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
              | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN
              | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
      }
      

    The systembar and navigation bar disappears. The reason for this is, because I have set IMMERSIVE_STICKY. It is whole lot of work to test it all around. I hope this helps you all, or atleast gives you the right direction.

    Remember, that a Fullscreen-Theme will always prevent you from scrolling while the softkeyboard is up. I am referencing to Android 4.4(KitKat).

提交回复
热议问题