[英]Prevent the keyboard from overflowing my LinearLayout after it shows up?
所以我正在嘗試構建一個聊天應用程序,它運行良好,但是當我嘗試打開鍵盤時遇到了這個問題。 這是沒有鍵盤的樣子:
] 1
這就是我單擊 並打開鍵盤時的樣子
我確實希望此功能保持不變,但我希望它不會溢出我的 LinearLayout
我通過使用這行代碼完成了這個功能:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
這是包含編輯文本和按鈕的線性布局的 xml 代碼:
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/blue_bar_background"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<EditText
android:id="@+id/et_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|start"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
android:background="@null"
android:ems="10"
android:focusedByDefault="true"
android:hint="Type a message "
android:maxLines="4"
android:minHeight="48dp"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:scrollHorizontally="true"
android:singleLine="false"
android:textColor="@color/white"
android:textColorHint="#A8FFFFFF"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_addMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_weight="0"
android:backgroundTint="@color/blue_bar_background"
android:clickable="true"
android:contentDescription="@string/app_name"
android:elevation="0dp"
android:src="@drawable/ic_round_send_24"
app:borderWidth="0dp"
app:elevation="0dp"
app:tint="@color/white" />
</LinearLayout>
如果您需要更多代碼,請在評論中告訴我。 非常感謝您的寶貴時間。
在PAN
中使用RESIZE
,這將使您的EditText
保持在 SoftKeyboard 上方。 這是示例-
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
或者您可以使用這樣的manifest
文件執行此操作 -
<activity
android:name=".YourActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize">
它過去對我有用,希望它有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.