我有一个在运行时加载片段的活动。当我启动应用程序时,活动将加载一个带有EditText的片段。我将ActionBarSherlock与splitActionBarWhenNarrow一起使用,所以我有一个拆分条(屏幕底部的操作条)。当EditText成为焦点并加载了软键盘时,它将移到拆分栏的顶部,将其隐藏。在操作栏上,我还使用NAVIGATION_MODE_LIST,并使用下拉菜单加载另一个片段。当我加载另一个片段时,即使我转到另一个片段,下部操作栏也会正确显示在软键盘的顶部,在该处它可以正常工作。我将添加一些屏幕截图来清除它:

第一个片段加载器,使用软键盘无法查看拆分条



使用操作栏导航加载第二个片段之后



重新加载另一个片段,操作栏仍然可见



我尝试使用最少的代码测试项目,只是为了加载片段,并且行为是相同的,拆分栏被软键盘隐藏。
如何使其从一开始就显示拆分栏?

编辑:android:windowSoftInputMode =“ adjustResize”不会更改此行为的任何内容

活动布局:

<it.bem.remailr.MyFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:orientation="horizontal"
android:background="@drawable/bg_no_repeat"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />


片段布局:

<it.bem.remailr.MyRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="top|left"
    android:inputType="textMultiLine|textNoSuggestions"
    android:windowSoftInputMode="adjustPan"
    android:background="#00000000"
    android:hint="@string/text_hint"
    android:scrollHorizontally="false" >
</EditText>

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />

最佳答案

您是否尝试过在显示输入法之后立即向主线程发布布局请求?您可以通过覆盖根onSizeChanged()中的View回调来确定是否显示/隐藏输入法。作为一个肮脏的概念证明,您可以在给定的持续时间之后发布该布局请求(确保事先显示输入方法)。

您也可以使用ViewServer在设备上运行hierarchyviewer,而不是在模拟器上运行,以便确定存在哪些View(也就是说,如果候选对象覆盖了拆分的操作栏)。从我的记忆中可以看出,候选视图还是添加到了包含Dialog的根KeyboardView中,因此拆分后的操作栏很可能就位于空格键的下方,而不是候选视图的下方。

为了实现onSizeChanged(),必须扩展位于ViewGroup层次结构根目录的View类。例如,您可能以LinearLayout作为根ViewGroup,而所有View都是此子级。然后,您要做的是创建一个名为MyLinearLayout的新类,该类扩展了LinearLayout,将MyLinearLayout作为您的根View放入xml文件中,然后实现onSizeChanged()回调。显示输入法后,系统将调用它。

关于android - Android软键盘隐藏拆分栏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13290228/

10-11 22:30
查看更多