android – (tablayout)当editText聚焦时,标签会越过键盘

前端之家收集整理的这篇文章主要介绍了android – (tablayout)当editText聚焦时,标签会越过键盘前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我用ViewPager setUp tabLayout,它有5个片段.
tabLayout与 android:layout_gravity设置为bottom.第三个片段有editText,当聚焦时,我的标签来自键盘.

Tablayout without EditText

TabLayout with EditText

主要布局:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.design.widget.CoordinatorLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:app="http://schemas.android.com/apk/res-auto"
  5. android:id="@+id/coordinatorLayout"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent">
  8.  
  9. <android.support.design.widget.AppBarLayout
  10. android:id="@+id/appBarLayout"
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content">
  13.  
  14. <include
  15. android:id="@+id/t"
  16. layout="@layout/toolbar"/>
  17.  
  18.  
  19. </android.support.design.widget.AppBarLayout>
  20.  
  21. <android.support.v4.view.ViewPager
  22. android:id="@+id/viewPager"
  23. android:layout_width="match_parent"
  24. app:layout_behavior="@string/appbar_scrolling_view_behavior"
  25. android:layout_height="match_parent"
  26. xmlns:android="http://schemas.android.com/apk/res/android"
  27. xmlns:app="http://schemas.android.com/apk/res-auto"/>
  28.  
  29. <android.support.design.widget.TabLayout
  30. android:layout_width="match_parent"
  31. android:layout_height="wrap_content"
  32. xmlns:app="http://schemas.android.com/apk/res-auto"
  33. xmlns:tab="http://schemas.android.com/tools"
  34. android:layout_gravity="bottom"
  35. app:tabGravity="fill"
  36. android:background="@color/colorPrimary"
  37. android:layout_alignParentBottom="true"
  38. android:id="@+id/tabs"
  39.  
  40. app:layout_collapseMode="parallax"
  41. app:layout_behavior="@string/appbar_scrolling_view_behavior"
  42.  
  43. xmlns:android="http://schemas.android.com/apk/res/android">
  44.  
  45.  
  46. </android.support.design.widget.TabLayout></android.support.design.widget.CoordinatorLayout>

第三片段布局:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical" android:layout_width="match_parent"
  4. android:layout_height="match_parent">
  5.  
  6. <EditText
  7. android:layout_width="match_parent"
  8. android:layout_height="wrap_content"
  9. android:layout_marginTop="40dp"
  10. android:hint="Enter something"
  11. />
  12. </LinearLayout>

解决方法

打开AndroidManifest.xml并添加到您的活动代码
机器人:windowSoftInputMode = “adjustPan”

如果这不起作用
机器人:windowSoftInputMode = “adjustNothing”

这将阻止软键盘调整布局.

希望这可以帮助.

猜你在找的Android相关文章