關於android的輸入法彈出來 覆蓋輸入框的問題

資源:吊炸天!74款APP完整源碼!



android 界面中 點擊輸入框時 彈出輸入法 如果輸入框在底部 會出現輸入法遮擋輸入內容的問題

解決辦法 設置activity的 window soft input mode 屬性,屬性具體參看google官方文檔或譯文(見後面)。

需要備註的是
1.使用adjustResize屬性是 如果界面中沒有滾動條 需要添加一個滾動條scrollview包裹所有內容,保證resize後 能滾動顯示顯示不下的內容
2.全屏fullscreen模式時 adjustResize屬性失效,屬於是一個bug,只能使用adjustPan 來設置焦點,比較悲劇
3.全屏fullscreen模式時 webview adjustPan 偶爾也會失效~~~~~~~~,悲劇一米




PS:
google官方文檔:
http://developer.android.com/gui ... -element.html#wsoft


譯文
http://www.blogjava.net/zhip/archive/2011/02/14/344258.html


bug:


全屏狀態下 adjustResize 不響應 只能用adjustpan,且webview 全屏狀態下 adjustpan響應也不夠好 有時無響應。

http://code.google.com/p/android/issues/detail?id=5497








[摘]android:windowSoftInputMode屬性使用
在AndroidManifest.xml文件中的android:windowSoftInputMode屬性使用

The AndroidManifest.xml File
  1. <activity android:windowSoftInputMode=["stateUnspecified",

  2.                                     "stateUnchanged", "stateHidden",

  3.                                     "stateAlwaysHidden", "stateVisible",

  4.                                     "stateAlwaysVisible", "adjustUnspecified",

  5.                                     "adjustResize", "adjustPan"] …… >

  6. </activity>
複製代碼
attributes:

android:windowSoftInputMode

活動的主窗口如何與包含屏幕上的軟鍵盤窗**互。這個屬性的設置將會影響兩件事情:

1>     軟鍵盤的狀態——是否它是隱藏或顯示——當活動(Activity)成爲用戶關注的焦點。

2>     活動的主窗口調整——是否減少活動主窗口大小以便騰出空間放軟鍵盤或是否當活動窗口的部分被軟鍵盤覆蓋時它的內容的當前焦點是可見的。

它的設置必須是下面列表中的一個值,或一個”state…”值加一個”adjust…”值的組合。在任一組設置多個值——多個”state…”values,例如&mdash有未定義的結果。各個值之間用|分開。例如: <activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >

在這設置的值(除"stateUnspecified"和"adjustUnspecified"以外)將覆蓋在主題中設置的值

值 描述

"stateUnspecified" 軟鍵盤的狀態(是否它是隱藏或可見)沒有被指定。系統將選擇一個合適的狀態或依賴於主題的設置。這個是爲了軟件盤行爲默認的設置。

"stateUnchanged" 軟鍵盤被保持無論它上次是什麼狀態,是否可見或隱藏,當主窗口出現在前面時。

"stateHidden" 當用戶選擇該Activity時,軟鍵盤被隱藏——也就是,當用戶確定導航到該Activity時,而不是返回到它由於離開另一個Activity。

"stateAlwaysHidden" 軟鍵盤總是被隱藏的,當該Activity主窗口獲取焦點時。

"stateVisible" 軟鍵盤是可見的,當那個是正常合適的時(當用戶導航到Activity主窗口時)。

"stateAlwaysVisible" 當用戶選擇這個Activity時,軟鍵盤是可見的——也就是,也就是,當用戶確定導航到該Activity時,而不是返回到它由於離開另一個Activity。

"adjustUnspecified" 它不被指定是否該Activity主窗口調整大小以便留出軟鍵盤的空間,或是否窗口上的內容得到屏幕上當前的焦點是可見的。系統將自動選擇這些模式中一種主要依賴於是否窗口的內容有任何佈局視圖能夠滾動他們的內容。如果有這樣的一個視圖,這個窗口將調整大小,這樣的假設可以使滾動窗口的內容在一個較小的區域中可見的。這個是主窗口默認的行爲設置。

"adjustResize" 該Activity主窗口總是被調整屏幕的大小以便留出軟鍵盤的空間。

"adjustPan" 該Activity主窗口並不調整屏幕的大小以便留出軟鍵盤的空間。相反,當前窗口的內容將自動移動以便當前焦點從不被鍵盤覆蓋和用戶能總是看到輸入內容的部分。這個通常是不期望比調整大小,因爲用戶可能關閉軟鍵盤以便獲得與被覆蓋內容的交互操作。





bug:

全屏狀態下 adjustResize 不響應 只能用adjustpan,且webview 全屏狀態下 adjustpan響應也不夠好 有時無響應。

http://code.google.com/p/android/issues/detail?id=5497

Issue 5497: adjustResize windowSoftInputMode breaks when activity is fullscreen   
  30 people starred this issue and may be notified of changes. Back to list 


Status:  New 
Owner:  ---- 
Type-Defect
Priority-Medium
ReportedBy-User 


Add a comment below   Reported by [email protected], Dec 16, 2009 
I am on Android 1.5 r3.  I have a very simple activity with a vertical
linear layout that contains an edit text, and a text view with a green
background that occupies all extra available space (layout weight = 1). 
When I focus on the edit text field, the keyboard appears and the screen
should get adjusted so that the green text view shrinks vertically
(resizes) and the text is still centered vertically within the visible
green space.  

This works great, except when I make the activity fullscreen - either by
setting the activity's theme to Theme.NoTitleBar.Fullscreen or by
programatically setting the FLAG_FULLSCREEN window flag.  If I use
Theme.NoTitleBar things are fine.

Also, I should mention that our device's screen is landscape (800x480) so I
have implemented a keyboard whose InputMethodService subclass overrides
onEvaluateFullscreenMode, always returning 'false' in order to stay in
'adjust resize keyboard mode' instead of going into 'fullscreen keyboard mode'.
TestAdjustResizeFullscreen.zip 
13.5 KB   Download  
ExpectedResult.png 
24.2 KB   View   Download  

FullscreenResult.png 
11.4 KB   View   Download  


Comment 1 by [email protected], Jan 31, 2010 
I see this as well. For my layout, I have a vertical LinearLayout. Within it, I have
these children from top to bottom: TextView, ListView, EditText, and finally a
horizontal LinearLayout, which in turn contains a button.

In my AndroidManifest.xml, I specified android:windowSoftInputMode="adjustResize",
and it works. The ListView shrinks as expected.

But when I change my theme to @android:style/Theme.Light.NoTitleBar.Fullscreen, the
adjustResize fails. My button at the bottom of the screen is obscured, and sometimes
part of the EditText is obscured until I start typing.
Comment 2 by [email protected], Jan 31, 2010 
Just to add a bit of detail to my previous comment: I see the failure on Android 1.6
on my G1 phone.
Comment 3 by [email protected], Jan 31, 2010 
Also tested on Android 2.1 in emulator - still fails there
Comment 4 by [email protected], Mar 1, 2010 
Does someone have a workaround? I suppose I could use a fixed height for my layout 
and tweak it when the keyboard displays, assuming I can compute the size of the 
remaining screen area.
Comment 5 by [email protected], Mar 7, 2010 
Reproducible on the Nexus One with 2.1-update1
Comment 6 by [email protected], Apr 24, 2010 
I would like to voice my opinion that a notification when the keyboard goes away
would be very helpful. I too am using a Fullscreen view, so I am stuck without an
option to know when the keyboard disappears.

I _am_ using a fixed height for the keyboard because the current mechanisms don't
seem to work for fullscreen. But when the user presses the back button, the IME eats
it and there's no notification or onSizeChanged to know when the keyboard goes away.

Why is it so hard to provide a notification when the keyboard goes away?
Comment 7 by [email protected], Aug 5, 2010 
Hello i have a relativeLayout at the top, then below i have a listView in the center and finaly at the bottom i have other relativeLayout with an editText and a button inside. I want to the listview resize when click the editText and the IME(virtual keyboard) appear. If i put adjustResize in the manifest, the listview is resized to leave space for the IME, but the relativeLayout with the editText that is below is cover by the IME and i can't see what i am writing. If i put adjustPan, the keyboard push up all, the listview is not resized and i loose the top relativeLayout. D: PLEASE HELP!!!! 
Comment 8 by [email protected], Sep 9, 2010 
i am facing the same issue what others are facing...if any one solve please let me know.
Comment 9 by [email protected], Oct 12, 2010 
I'm running into this same issue with an activity that has an embedded WebView. The input field keyboard focus doesn't work right without adjustResize turned on, but adjustResize doesn't work in full screen mode. This means that this is the only activity in my app that shows the status bar. At the very least there should be something in the documentation that says that this combination doesn't (or isn't supposed to) work.
Comment 10 by project member [email protected], Oct 13, 2010 
Relevant post from hackbod:
https://groups.google.com/group/ ... sg/5690ac3a9819a53b
Comment 12 by [email protected], Feb 1, 2011 
Please patch the OS so that adjustPan is honored in a fullscreen webview : 

When a keyboard slides up in a fullscreen webview, the input field clicked on should slide up (remaining visible). 

Otherwise, web designers cannot place input fields on the bottom 2/3rds of a screen.
Comment 13 by [email protected], Feb 23, 2011 
I can confirm this issue. As soon as you set your activity to fullscreen the windowSoftInputMode:adjustResize will no longer work.

I hope this will get fixed soon as this break alot of layout ideas.
Comment 14 by [email protected], Mar 16, 2011 
Still an issue. 2.2.1
Comment 16 by [email protected], Sep 9, 2011 
The same issue occurs in Android 3.1.

The notification is also NOT SENT when the device is in LANDSCAPE mode in versions prior to 3.0. (actually i tested it in a Xoom with 3.1 and the notification is sent in LANDSCAPE mode, so i'm just assuming it was fixed in 3.0). The fullscreen problem also occurs in xoom, even if there's no screen diference between full screen and non-full screen in the Xoom.
Comment 17 by akasek, Oct 7, 2011 
The last two comments have confirmed Froyo and Honeycomb. I'll confirm Gingerbread also (2.3.4)

Also, I interpret the linked post in comment 10 from Diane Hackborn as acknowledgement that this is an unintended effect and should not be the case.

Would be nice if this was fixed, because adjustPan does bad things to layouts with headers or footers (pushing them offscreen).  In an application which allows the user to select whether to hide the status bar or not, the time when the most space is available is the time when header and footer elements will become unaccessible.  It doesn't make sense to behave this way. 




Java和Android架構

Java和Android架構是一個數萬人關注的探討Java和Android開發的公衆號,分享和原創最有價值的乾貨文章,讓你成爲這方面的大牛!

我們探討android和Java開發最前沿的技術:android性能優化 ,插件化,跨平臺,動態化,加固和反破解等,也討論設計模式/軟件架構等。由羣來自BAT的工程師組成的團隊

關注即送紅包,回覆:“百度” 、“阿里”、“騰訊” 有驚喜!!!關注後可用入微信羣。羣裏都是來自百度阿里騰訊的大牛。

歡迎關注我們,一起討論技術,掃描和長按下方的二維碼可快速關注我們。搜索微信公衆號:JANiubility。

公衆號:JANiubility



發佈了26 篇原創文章 · 獲贊 4 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章