如何避免软键盘推高我的布局?

我有一组导航button坐在每个活动的底部。 在一些活动中,我需要在其顶部的searchtextview。 但是,只要用户在文本视图中键入内容,软键盘总是会popup我的导航button,即使它实际上并没有阻止文本视图。 这使得我的UI看起来很有趣。 我怎样才能强制我的导航button保持静态,而不被软键盘按压? 我试图设置活动的windowSoftInputMode,但没有configuration帮助。

有什么build议么? 谢谢

我确实有同样的问题,起初我补充说:

<activity android:name="com.companyname.applicationname" android:windowSoftInputMode="adjustPan"> 

到我的清单文件。 但是,这本身并没有解决这个问题。 那么正如Artem Russakovskii提到的那样,我补充道:

 <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:isScrollContainer="false"> </ScrollView> 

在scrollview中。

这是为我工作。

在我的情况下,button被推上去的原因是因为他们上面的视图是一个ScrollView ,并且无论我设置的android:windowSoftInputMode值是什么值,它都会按下键盘上方的button。

我能够通过设置避免我的底部一排button被软键盘推上去

 android:isScrollContainer="false" 

在button上方的ScrollView上。

要解决这个问题,只需在android清单文件中添加android:windowSoftInputMode="stateVisible|adjustPan

 <activity android:name="com.comapny.applicationname.activityname" android:screenOrientation="portrait" android:windowSoftInputMode="stateVisible|adjustPan"/> 

为未来的读者。

我想要对这个问题进行具体的控制,所以这就是我所做的:

从片段或活动中,隐藏其他视图(键盘启动时不需要),然后恢复它们以解决此问题:

 rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); rootView.getWindowVisibleDisplayFrame(r); int heightDiff = rootView.getRootView().getHeight() - (r.bottom - r.top); if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard... //ok now we know the keyboard is up... view_one.setVisibility(View.GONE); view_two.setVisibility(View.GONE); } else { //ok now we know the keyboard is down... view_one.setVisibility(View.VISIBLE); view_two.setVisibility(View.VISIBLE); } } }); 

windowSoftInputMode将平移或调整您的活动布局。 你可以做的一件事就是将一个onFocusChanged监听器附加到你的EditText上,当用户select/点击EditText时,你隐藏或者移动你的导航button。 当EditText失去焦点时,您可以将导航button放回到活动的底部。

我有同样的问题,但设置windowSoftInputMode没有帮助,我不想改变上部视图有isScrollContainer="false"因为我想要滚动。

我的解决scheme是定义导航工具的顶部位置,而不是底部。 我正在使用titanium,所以我不知道这将如何转换为Android。 定义导航工具视图的顶部位置可防止软键盘将其推上,而是像我想要的那样覆盖导航控件。

通过设置顽皮的EditText解决了它:

 etSearch = (EditText) view.findViewById(R.id.etSearch); etSearch.setInputType(InputType.TYPE_NULL); etSearch.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { etSearch.setInputType(InputType.TYPE_CLASS_TEXT); return false; } });