[英]Android: Adjust the buttons above soft keyboard on clicking edittext
我正在嘗試調整圖像按鈕正下方的軟鍵盤,但它覆蓋了無法點擊的圖像按鈕。 當用戶單擊編輯文本時,我希望按鈕位於軟鍵盤的正上方。 我曾嘗試使用windowSoftInputMode="adjustResize"
,但它似乎不起作用。
下面是我的 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>
在我的 AndroidManifest.xml 文件中
<activity
android:name=".AddNote"
android:exported="true"
android:windowSoftInputMode="adjustResize"/>
試試這個代碼,這將在鍵盤上方顯示按鈕。 當我們確實想在鍵盤上方顯示任何視圖時,該視圖應該底部對齊。
<?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.