英文:
how to resize bottomsheet when keyboard is opened?
问题
我使用了一个BottomSheet,我已经定义为STATE_EXPANDED。在底部表单中,我有3个编辑框。我在底部表单打开时强制打开了编辑框。当底部表单打开时,键盘同时打开。到目前为止都没有问题。我在LinearLayout中使用了android:windowSoftInputMode="stateVisible|adjustResize"。当底部表单打开时,会出现以下图像:
但是我的目标是这样的:
我指的是,当底部表单打开时选择编辑框时,我希望底部的空间能够与键盘的高度一样,以便菜单出现。
以下是我的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="?attr/bottombarcolor"
android:windowSoftInputMode="stateVisible|adjustResize"
android:fitsSystemWindows="true">
<!-- 这里放置了其他的布局元素 -->
</LinearLayout>
当我点击底部的编辑框时,我想要的情况发生了。我希望当选择第一个编辑框时也能发生这种情况。
英文:
I am using one BottomSheet which I have defined as STATE_EXPANDED.I have 3 edittext in bottomsheet.I did force edittext when bottomsheet opened.When bottomsheet is opened keyboard is opened at the same time.so far no problem.im using android:windowSoftInputMode="stateVisible|adjustResize" in Linearlayout.When bottomsheet is opened, an image like this occurs;
but my goal is here;
I mean, when edittext is selected when botttomsheet is opened, I want the space at the bottom to be as much as the keyboard for the menu to appear.
here are my codes;
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:gravity="center_horizontal"
android:orientation="vertical"
android:background="?attr/bottombarcolor"
android:windowSoftInputMode="stateVisible|adjustResize"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:orientation="horizontal"
android:layout_marginBottom="10dp"
android:backgroundTint="?attr/colorPrimary">
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_back"
style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
android:layout_width="60dp"
android:layout_weight="0"
android:layout_height="match_parent"
android:layout_gravity="center"
android:textColor="?attr/textcolor"
app:icon="@drawable/ic_arrow_back_black_24dp"
app:iconGravity="start"
app:iconTint="?attr/colorPrimary"
android:backgroundTint="?attr/bottombarcolor"/>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/dropdownlist"
app:hintTextColor="?attr/colorPrimary"
app:boxBackgroundColor="?attr/bottombarcolor"
android:layout_weight="1"
android:textColorHint="?attr/textcolor"
app:boxCollapsedPaddingTop="2dp">
<AutoCompleteTextView
android:id="@+id/filled_exposed_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="sdfsdfsfsg"
android:inputType="none"
android:fontFamily="@font/regularopensans"
android:textColor="?attr/textcolor" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_apply"
style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
android:layout_width="60dp"
android:layout_weight="0"
android:layout_height="match_parent"
android:layout_gravity="center"
android:textColor="?attr/textcolor"
app:icon="@drawable/ic_check_black_24dp"
app:iconGravity="end"
app:iconTint="?attr/colorPrimary"
/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="16dp"
android:background="@android:color/white"
android:backgroundTint="?attr/colorPrimary"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:text="@string/newtask"
android:textColor="?attr/textcolor"
android:fontFamily="@font/regularopensans"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/outlinedTfNew"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/entertask"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:hintTextColor="?attr/colorPrimary"
android:textColorHint="?attr/textcolor"
app:boxStrokeColor="?attr/textcolor"
app:boxStrokeWidth="0dp"
app:endIconMode="clear_text"
app:startIconDrawable="@drawable/ic_mic_black_24dp"
app:endIconTint="?attr/colorPrimary"
app:startIconTint="?attr/colorPrimary">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/txteditNew"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/textcolor"
android:fontFamily="@font/lightopensans" />
<requestFocus />
</com.google.android.material.textfield.TextInputLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="16dp"
android:background="@android:color/white"
android:backgroundTint="?attr/textcolor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/taskcompdate"
android:textColor="?attr/textcolor"
android:textAlignment="center"
android:fontFamily="@font/regularopensans"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/outlinedTfComp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/nodate"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:hintTextColor="?attr/colorPrimary"
android:textColorHint="?attr/textcolor"
app:boxStrokeColor="?attr/textcolor"
app:boxStrokeWidth="0dp"
app:endIconMode="clear_text"
app:startIconTint="?attr/colorPrimary"
app:startIconDrawable="@drawable/ic_today_black_24dp"
app:endIconTint="?attr/colorPrimary">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/textcolor"
android:fontFamily="@font/lightopensans"/>
</com.google.android.material.textfield.TextInputLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="16dp"
android:background="@android:color/white"
android:backgroundTint="?attr/textcolor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tasktime"
android:textColor="?attr/textcolor"
android:fontFamily="@font/regularopensans"
android:textAlignment="center"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/outlinedTfTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/notime"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:hintTextColor="?attr/colorPrimary"
android:textColorHint="?attr/textcolor"
app:boxStrokeColor="?attr/textcolor"
app:boxStrokeWidth="0dp"
app:endIconTint="?attr/colorPrimary"
app:endIconMode="clear_text"
app:startIconDrawable="@drawable/ic_access_time_black_24dp"
app:startIconTint="?attr/colorPrimary">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/textcolor"
android:fontFamily="@font/lightopensans" />
</com.google.android.material.textfield.TextInputLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="16dp"
android:background="@android:color/white"
android:backgroundTint="?attr/textcolor"
/>
When I click on the bottom edittext, the situation I want occurs.I want this to happen when the first edittext is selected.
专注分享java语言的经验与见解,让所有开发者获益!
评论