在android中将文本光标位置设置在软键盘上方 [英] Make text cursor position above soft keyboard in android
问题描述
我在ScrollView中有一些多行EditText控件。当我点击任何EditText控件时,软键盘出现,
但是EditText及其光标位置出现在键盘后面。我需要手动将视图滚动到顶部。
有没有办法解决这个问题?在下面的代码中,cameraButton总是出现在键盘上方。
I have a some multiline EditText controls in a ScrollView. When I tap any of the EditText controls, the soft keyboard appears,
but the EditText and its cursor position appears behind the keyboard. I need to manually scroll the view to top.
Is there any way to fix this issue? In the below code cameraButton always appear above the keyboard.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/crlayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ScrollView
android:id="@+id/scrollview"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/boxImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
/>
<EditText
android:id="@+id/new_box_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Title"
android:inputType="textPersonName" />
<EditText
android:id="@+id/new_box_descri"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Description"
android:gravity="top"
android:inputType="textCapSentences|textMultiLine"
android:lines="5"
android:windowSoftInputMode="stateAlwaysVisible" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="@android:color/white"
>
<ImageButton
android:id="@+id/cameraButton"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="1"
android:contentDescription="Open Camera"
app:srcCompat="@drawable/ic_box_camera_icon"
android:background="?attr/selectableItemBackgroundBorderless"
/>
</LinearLayout>
</RelativeLayout>
我尝试了什么:
我尝试在EditText上滚动scrollView到底点击,但这不会起作用键盘出现在EditText onClick之后,布局调整为键盘显示。
What I have tried:
I tried scrolling the scrollView to bottom on EditText Click, But this won't work as the keyboard appears after the EditText onClick, and layout resized as keyboard appears.
推荐答案
在清单文件中为此活动添加以下代码
In Manifest file add the below code for this activity
<activity android:windowSoftInputMode="adjustPan">
如果以上方法不起作用,请试试这个
If above method does not work then try this one
android:windowSoftInputMode="stateVisible|adjustResize"
这篇关于在android中将文本光标位置设置在软键盘上方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!