Activity fullScreen Theme样式导致输入法显示问题。

来源:互联网 发布:淘宝卖家怎么报名双11 编辑:程序博客网 时间:2024/06/06 07:23

问题表象:

今天在移植部分代码时,出现了输入法的menu栏不显示的问题。如上图图二。
细心观察会有3处不同:

  • 输入法栏显示不全
  • actionBar的头部不显示问题。
  • 图1ListView没有滚动,图2整体向上滚动

问题原因

activity配置如下

<activity    android:name="***.PostDetailActivity"    android:configChanges="orientation|keyboard|keyboardHidden|screenSize"    android:screenOrientation="portrait"    android:theme="@android:style/Theme.Translucent.NoTitleBar.FullScreen"    android:windowSoftInputMode="stateAlwaysHidden|adjustResize">            </activity>

layout 配置文件结构如下:

代码移植后,layout配置文件未做大的修改,代码Activity,fragment也未做输入法相关的改动。
细心翻看代码提交记录,还有点点经验,感觉可能是manifest配置文件的问题,于是做了比较,果然android:theme不同。怀疑是这个原因导致的。

由于使用了android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"adjustResize
fullScreen属性导致adjustResize参数不起作用。

深挖 问题原因

请看文档:
https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_FULLSCREEN

FLAG_FULLSCREEN
added in API level 1
int FLAG_FULLSCREEN
Window flag: hide all screen decorations (such as the status bar) while this window is displayed. This allows the window to use the entire display space for itself -- the status bar will be hidden when an app window with this flag set is on the top layer. A fullscreen window will ignore a value of SOFT_INPUT_ADJUST_RESIZE for the window's softInputMode field; the window will stay fullscreen and will not resize.
This flag can be controlled in your theme through the windowFullscreen attribute; this attribute is automatically set for you in the standard fullscreen themes such as Theme_NoTitleBar_Fullscreen, Theme_Black_NoTitleBar_Fullscreen, Theme_Light_NoTitleBar_Fullscreen, Theme_Holo_NoActionBar_Fullscreen, Theme_Holo_Light_NoActionBar_Fullscreen, Theme_DeviceDefault_NoActionBar_Fullscreen, and Theme_DeviceDefault_Light_NoActionBar_Fullscreen.

意思就是使用FullScreen后,SOFT_INPUT_ADJUST_RESIZE将不在起作用。

若你必须使用FullScreen,可以参考下面给出的解决方案:
http://stackoverflow.com/a/30019136/325479
这里也有这个问题的很多讨论:
https://code.google.com/p/android/issues/detail?id=5497&q=fullscreen&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

参考

  • http://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible/19494006#19494006
  • 这里也有这个问题的很多讨论:https://code.google.com/p/android/issues/detail?id=5497&q=fullscreen&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
0 0