键盘隐藏在EditTexts片段 [英] Keyboard hiding EditTexts in Fragments
问题描述
编辑:
我需要使用键盘,但它隐藏我的的EditText
,我需要它来滚动,键盘没有隐藏它。
edit:
I need to use the keyboard, but it hides my EditText
, I need it to scroll so the keyboard is not hiding it.
我使用的是三星平板。
我的风格:
parent="android:Theme.Holo.NoActionBar.Fullscreen"
的的EditText
字段可滚动视图中,像这样:
The EditText
fields are in a scrollable view, like so:
片段布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ScrollView
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="@string/depot_code"/>
<EditText
android:hint="@string/enter_depot_code"
android:id="@+id/etlocationId"
android:imeOptions="actionNext"
android:inputType="number"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="12"
android:singleLine="true">
<requestFocus/>
</EditText>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="@string/name"/>
<EditText
android:hint="@string/enter_name"
android:id="@+id/etname"
android:imeOptions="actionNext"
android:inputType="textPersonName"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="24"
android:singleLine="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="@string/street"/>
<EditText
android:hint="@string/enter_street"
android:id="@+id/etstreet"
android:imeOptions="actionNext"
android:inputType="textPostalAddress"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="24"
android:singleLine="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="@string/suburb"/>
<EditText
android:hint="@string/enter_suburb"
android:id="@+id/etsuburb"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="24"
android:singleLine="true"/>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="@string/state"/>
<Spinner
android:focusable="true"
android:focusableInTouchMode="true"
android:id="@+id/spinner"
android:imeOptions="actionNext"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="fill_parent"
android:spinnerMode="dropdown"/>
<TextView
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="@string/phone"/>
<EditText
android:hint="@string/enter_phone"
android:id="@+id/etphone"
android:imeOptions="actionDone"
android:inputType="phone"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:lines="1"
android:maxLength="12"
android:singleLine="true"/>
<Button
android:id="@+id/btnadd"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:text="@string/add"/>
</LinearLayout>
</ScrollView>
</FrameLayout>
该活动布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tech_controller"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
< .../ Layouts. ../>
<FrameLayout
android:id="@+id/second"
android:layout_height="match_parent"
android:layout_width="fill_parent"/>
</LinearLayout>
类似的问题已经被问过,但我还没有找到问题的答案。
Similar questions have been asked, but I have not found an answer that works.
我有一个使用连接到一个活动的碎片的项目。
在我的清单的活动我有:
I have a project that uses many fragments attached to the one activity. In my manifest for the activity I have:
android:windowSoftInputMode="stateHidden"
一些片段要求用户输入。
Some of the fragments require user input.
在片段布局我使用:
每个片段嵌套如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent" .../>
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<EditText
android:imeOptions="actionNext"
or
android:imeOptions="actionDone" .../>
这工作得很好。除
键盘隐藏了位于下部页面上的EditTexts
This works well. EXCEPT the keyboard hides the EditTexts that are positioned lower on the page.
我已阅读本一遍又一遍:
I have read this over and over:
<一个href=\"http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions\">http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions
尝试了这些建议,但键盘是那么明显的活动时被调用,这是我不想要的。它也不起作用。也许是因为它是一个片段
Tried these suggestions, but the keyboard is then visible when the activity is called, which I don't want. It also does not work. Maybe because it is a fragment?
我一直在试图找出一个动态的解决方案。任何帮助是AP preciated。
I have been trying to work out a dynamic solution. Any help is appreciated.
编辑:这是在平板电脑上使用,只有一个键盘的选择,用语言的变化
编辑:我的解决方案
我已经安装其他软键盘解决它。 <一href=\"https://$c$c.google.com/p/softkeyboard/wiki/HowTo\">https://$c$c.google.com/p/softkeyboard/wiki/HowTo
I have solved it by installing another soft keyboard. https://code.google.com/p/softkeyboard/wiki/HowTo
推荐答案
尝试调用 InputMethodManager.hideSoftInputFromWindow()
在你的片段的 onActivityCreated()在这个功能href=\"http://stackoverflow.com/a/9981958\"> SO回答?
Try to call InputMethodManager.hideSoftInputFromWindow()
during your fragment's onActivityCreated()
function mentioned in this SO answer?
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AppUtil.hideKeyboard(getActivity(), getView());
}
其中, hideKeyboard()
看起来像这样
public static void hideKeyboard(Activity activity, View viewToHide) {
InputMethodManager imm = (InputMethodManager) activity
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(viewToHide.getWindowToken(), 0);
}
这篇关于键盘隐藏在EditTexts片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!