和很多人一样,我遇到了软输入覆盖我的发送按钮的问题,所以我做了一些搜索,发现解决这个问题的公认方法是"android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
这在我的设备上运行得很好,但是当我在我女朋友的手机上尝试它时,它不起作用。在输入显示在屏幕上之前,我看到对话框稍微抬起了一点,但幅度不大,并且发送按钮仍然被覆盖。为什么这适用于某些设备,但不适用于所有设备?
在我的活动视图RelativeLayout中,有两种布局:LinearLayout-“ ll ”(必须在屏幕顶部)和相对布局-“ rl”(必须在屏幕底部)。当我在ll中专注于editText时,它会打开键盘,而 rl会上升并显示在ll上。然后我尝试使用,android:layout_below="@+id/ll"但是没有用。我也尝试android:windowSoftInputMode=""在清单中添加各种参数,但没有任何帮助。
所以,即使键盘打开,如何保持RelativeLayout“ rl”在屏幕底部?
这是代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="@dimen/main_container_padding"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:xxx="http://schemas.android.com/apk/res-auto" >
<!-- Layout of username, password, Sign in button -->
<LinearLayout
android:id="@+id/llusernamePassLogin"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal" >
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="@string/loginPageText" />
<am.bs.xxx.view.EditTextBase
android:id="@+id/login_vcardnumber"
android:layout_width="fill_parent"
android:layout_height="@dimen/edit_text_height"
android:layout_margin="@dimen/edit_text_margin"
android:hint="@string/email"
android:inputType="text" />
<am.bs.xxx.view.EditTextBase
android:id="@+id/login_password"
android:layout_width="fill_parent"
android:layout_height="@dimen/edit_text_height"
android:layout_margin="@dimen/edit_text_margin"
android:hint="@string/password"
android:inputType="textPassword" />
<Button
android:id="@+id/signin"
style="@style/main_button"
android:layout_width="fill_parent"
android:layout_height="@dimen/edit_text_height"
android:layout_margin="@dimen/edit_text_margin"
android:background="@drawable/main_button_shape_selector"
android:onClick="createButtonClickListener"
android:text="@string/signIn" …Run Code Online (Sandbox Code Playgroud) android relativelayout android-layout android-softkeyboard window-soft-input-mode
即使这个问题在stackoverflow中有很多解决方案,我也无法解决我的问题。我在屏幕上有两个编辑文本,一个在顶部,另一个附加在屏幕底部。每当我点击底部编辑文本时,软键盘就会出现在它上面。我已经玩过 windowSoftInputMode。
当我单击底部的编辑文本时,我不希望屏幕的其他内容向上滚动。
这是我的 xml 布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@color/background"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/phone_number_edit_text_compose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_toLeftOf="@id/select_contact"
android:background="@drawable/phone_edittext_background_selector"
android:ems="10"
android:hint="@string/phone_edittext_hint"
android:inputType="phone"
android:paddingBottom="12dp"
android:paddingLeft="8dp"
android:paddingTop="12dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white" />
<ImageButton
android:id="@+id/selectcontact_compose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/phone_number_edit_text_compose"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_toRightOf="@id/phone_number_edit_text_compose"
android:background="@drawable/select_contact_background_selector"
android:contentDescription="@string/select_contact_content_description"
android:src="@drawable/select_contact_selector"
android:layout_marginLeft="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"/>
<View
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="2px"
android:layout_below="@id/phone_number_edit_text_compose"
android:layout_marginTop="@dimen/redial_screen_distance_between_views"
android:background="@drawable/separator" />
<LinearLayout
android:id="@+id/repetition_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view1"
android:clickable="true"
android:onClick="RepetitionLayoutClickListener"
android:orientation="horizontal"
android:paddingBottom="@dimen/redial_screen_distance_between_views"
android:paddingTop="@dimen/redial_screen_distance_between_views"
android:background="@drawable/repetition_layout_background_selector"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<TextView
android:id="@+id/repetition_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/repetition" …Run Code Online (Sandbox Code Playgroud) xml android android-layout window-soft-input-mode android-relativelayout
在清单中使用 adjustPan 会将我的布局推到顶部,并使我的 UI 看起来很可笑。

这是我的 Android 清单:
<activity
android:name=".AddNote"
android:label="@string/title_activity_add_note"
android:windowSoftInputMode="stateVisible|adjustPan">
Run Code Online (Sandbox Code Playgroud)
这是我的 XML 文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.dinosaur.cwfei.materialnotes.AddNote">
<include
android:id="@+id/app_bar"
layout="@layout/app_bar_no_spinner" />
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/cardview_margin">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_vertical_margin"
android:orientation="vertical">
<EditText
android:id="@+id/editTextTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_16"
android:background="@color/transparent"
android:hint="@string/hint_title"
android:textStyle="bold" />
<EditText
android:id="@+id/editTextDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:hint="@string/hint_note" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="@dimen/margin_16"
android:layout_marginTop="100dp"
android:background="@color/divider_color" />
</LinearLayout>
</ScrollView>
</android.support.v7.widget.CardView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我在 LazyColumn 内的 TextFields 遇到问题。
我的目标是拥有一个带有一堆 TextFields 的 LazyColumn,我可以
那是我的代码:
LazyColumn(
modifier = Modifier.background(Color.Blue)
) {
items(count = 20, key = { it }) {
var text by remember { mutableStateOf("$it.") }
OutlinedTextField(
value = text,
onValueChange = { text = it },
modifier = Modifier
.fillMaxWidth()
.padding(2.dp)
.background(Color.Gray)
)
}
}
Run Code Online (Sandbox Code Playgroud)
问题:
使用此代码时,当 TextField 位于列底部时,键盘将隐藏所有新行。您可以手动向下滚动并查看新行,但这不是理想的解决方案。另外,如果其下方有更多文本字段,它们将被隐藏,无法通过滚动到达,因此,如果我想先在 TextField 17 中输入文本,然后在 TextField 18 中输入文本,则必须在两者之间关闭键盘。
试图:
我尝试通过android:windowSoftInputMode="adjustResize"在 AndroidManifest 中进行设置来解决此问题,但是当我单击屏幕底部的 TextField 时,LazyColumn 会滚动并且键盘会关闭。
这里对此行为有一个很好的解释,建议是
现在,解决方法包括使用列,而不是惰性列;使用自定义惰性可组合项创建您自己的惰性列,并手动处理可组合项的堆大小,以便最终字段不会失去组合。
假设我有大量的 …
android window-soft-input-mode android-jetpack-compose android-compose-textfield lazycolumn
我想知道 2 件事
如何始终显示软键盘并且不让它关闭(即使按下后退或确定按钮)?
我怎样才能从中获得输入?
我已经尝试过这段代码:
EditText yourEditText= (EditText) findViewById(R.id.ed);
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
Run Code Online (Sandbox Code Playgroud)
具有这些变体:
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);imm.toggleSoftInputFromWindow( yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);keyboard android android-keypad android-edittext window-soft-input-mode