[英]Android: Adjust the buttons above soft keyboard on clicking edittext
I am trying to adjust the softkeyboard right below the image buttons, but it covers the image buttons which does not makes it clickable .我正在尝试调整图像按钮正下方的软键盘,但它覆盖了无法点击的图像按钮。 I want the buttons to be right above the softkeyboard when the user clicks on the edittext.
当用户单击编辑文本时,我希望按钮位于软键盘的正上方。 I have tried using the
windowSoftInputMode="adjustResize"
, but it does not seem to work.我曾尝试使用
windowSoftInputMode="adjustResize"
,但它似乎不起作用。
Below is my layout.xml file下面是我的 layout.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/addnote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="@color/white" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/addnote_title"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:hint="Title">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/addnote_title_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="23dp"
tools:layout_editor_absoluteY="28dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/addnote_descp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:hint="Notes">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/addnote_descp_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:lines="10"
tools:layout_editor_absoluteX="23dp"
tools:layout_editor_absoluteY="28dp" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="2dp">
<ImageButton
android:id="@+id/check_btn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@color/black"
android:layout_marginRight="2dp"
android:src="@drawable/checkbox"/>
<ImageButton
android:id="@+id/bold_btn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@color/black"
android:layout_marginLeft="2dp"
android:src="@drawable/format_bold"/>
</LinearLayout>
</LinearLayout>
and in the AndroidManifest.xml file i have在我的 AndroidManifest.xml 文件中
<activity
android:name=".AddNote"
android:exported="true"
android:windowSoftInputMode="adjustResize"/>
Try this code this will show buttons above the keyboard.试试这个代码,这将在键盘上方显示按钮。 When we do want to display any view above the keyboard that view should be aligned bottom.
当我们确实想在键盘上方显示任何视图时,该视图应该底部对齐。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/addnote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:titleTextColor="@color/white" />
<ScrollView
android:layout_width="match_parent"
android:layout_below="@id/my_toolbar"
android:layout_marginBottom="20dp"
android:layout_above="@id/bottom_layout"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/addnote_title"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:hint="Title">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/addnote_title_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="23dp"
tools:layout_editor_absoluteY="28dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/addnote_descp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
android:hint="Notes">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/addnote_descp_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:lines="10"
tools:layout_editor_absoluteX="23dp"
tools:layout_editor_absoluteY="28dp" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:padding="2dp">
<ImageButton
android:id="@+id/check_btn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@color/black"
android:layout_marginRight="2dp"/>
<ImageButton
android:id="@+id/bold_btn"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@color/black"
android:layout_marginLeft="2dp"/>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.