Yve*_*omb 17 android android-fragments samsung-mobile window-soft-input-mode imeoptions
编辑:我需要使用键盘,但它隐藏了我的EditText,我需要它滚动,所以键盘没有隐藏它.
我正在使用三星平板电脑.
我的风格:
parent="android:Theme.Holo.NoActionBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)
这些EditText字段位于可滚动视图中,如下所示:
片段布局:
<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>
Run Code Online (Sandbox Code Playgroud)
活动布局:
<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>
Run Code Online (Sandbox Code Playgroud)
有人问过类似的问题,但我没有找到有效的答案.
我有一个项目,它使用附加到一个活动的许多片段.在我的活动清单中:
android:windowSoftInputMode="stateHidden"
Run Code Online (Sandbox Code Playgroud)
一些片段需要用户输入.
在我使用的片段布局中:
每个片段嵌套如下:
<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" .../>
Run Code Online (Sandbox Code Playgroud)
这很好用.除键盘外,还会隐藏位于页面下方的EditTexts.

我一遍又一遍地读到这个:
http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions
试过这些建议,但是当调用活动时键盘可见,这是我不想要的.它也行不通.也许是因为它是片段?
我一直在尝试制定动态解决方案.任何帮助表示赞赏.
编辑:这是在平板电脑上使用,只有一个键盘选项,语言更改.
编辑:我的解决方案
我通过安装另一个软键盘解决了这个问题.https://code.google.com/p/softkeyboard/wiki/HowTo
尝试使用WindowsSoftInputMode作为adjustpan唯一的.
例如:
android:windowSoftInputMode="adjustPan"
Run Code Online (Sandbox Code Playgroud)
尝试在此SO回答中提到InputMethodManager.hideSoftInputFromWindow()的片段onActivityCreated()功能期间调用?
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AppUtil.hideKeyboard(getActivity(), getView());
}
Run Code Online (Sandbox Code Playgroud)
这里hideKeyboard()看起来像这样
public static void hideKeyboard(Activity activity, View viewToHide) {
InputMethodManager imm = (InputMethodManager) activity
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(viewToHide.getWindowToken(), 0);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11790 次 |
| 最近记录: |