Hei我目前正在尝试创建具有以下布局的BottomSheetDialogFragment:
@IBOutlet weak var someButton: UIButton!
@IBAction func someButton(_ sender: UIButton) {
UIView.transition(with: sender, duration: 0.3, options: .transitionCrossDissolve, animations: {
sender.setImage(UIImage(named: "My Image.png"), for: UIControl.State.highlighted)
}, completion: nil)
//...other functions
}
这里的目的是使出现的softinput调整大小并在整个布局下定位,而不是平移到edttextfields。基于对如何使它与<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:layout_alignParentBottom="true">
<com.indico.recorder.views.DonkeyConstraintLayout
android:id="@+id/album_edit_info_container"
android:layout_width="match_parent"
android:backgroundTint="@color/colorBackgroundTinted"
android:layout_height="wrap_content"
android:clipChildren="true"
android:clipToPadding="true">
<View
android:id="@+id/album_edit_draggable_indicator"
android:layout_width="40dp"
android:layout_height="4dp"
android:alpha="0.65"
android:background="@drawable/draggable_indicator"
app:layout_constraintBottom_toTopOf="@id/album_edit_title_container"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:elevation="1dp"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/album_edit_title_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintTop_toBottomOf="@id/album_edit_draggable_indicator"
app:layout_constraintBottom_toTopOf="@id/album_edit_description_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<com.indico.recorder.views.AutoClearEditText
android:id="@+id/album_edit_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLength="@integer/media_title_max_length"
android:hint="@string/session_name_hint"
android:imeOptions="actionNext"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/album_edit_description_container"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toTopOf="@id/albumEditDivider"
app:layout_constraintTop_toBottomOf="@id/album_edit_title_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<android.support.design.widget.TextInputEditText
android:id="@+id/album_edit_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="75dp"
android:textAlignment="textStart"
android:inputType="textMultiLine|textAutoCorrect|textCapSentences"
android:maxLines="@integer/media_description_max_length"
android:hint="@string/session_description_hint"
android:gravity="start|top"
android:visibility="visible"/>
</android.support.design.widget.TextInputLayout>
<View
android:id="@+id/albumEditDivider"
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:alpha="0.75"
android:background="@drawable/divider_horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/album_edit_description_container"
app:layout_constraintStart_toStartOf="parent"/>
</com.indico.recorder.views.DonkeyConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="@+id/album_edit_activate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:padding="16dp"
android:background="@drawable/capture_selection_item_background">
<ImageView
android:id="@+id/album_edit_activate_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/ic_check_white_24dp"
android:layout_gravity="center"
android:tint="@color/colorPrimary"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:id="@+id/album_edit_activate_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginStart="16dp"
android:text="@string/album_edit_activate"
android:layout_centerInParent="true"
android:textColor="@color/colorOnSurface"
android:textSize="20sp"
app:layout_constraintStart_toEndOf="@id/album_edit_activate_icon"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
结合使用以及其他窗口属性的大量研究得出的结论,导致我所有底页的样式如下:
fitSystemWindows
我未在清单中指定<style name="BottomSheet.Theme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/BottomSheet.Style</item>
<item name="windowNoTitle">true</item>
<item name="android:label">@null</item>
<item name="android:fitsSystemWindows">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowSoftInputMode">adjustPan|stateVisible</item>
<item name="android:windowClipToOutline">true</item>
</style>
<style name="BottomSheet.Style" parent="Widget.Design.BottomSheet.Modal">
<item name="behavior_peekHeight">300dp</item>
<item name="android:background">@drawable/squared_card_background</item>
<item name="behavior_hideable">true</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowSoftInputMode">adjustPan|stateVisible</item>
</style>
,因为其余应用程序需要默认行为。
底页片段:
windowSoftInputMode
任何有关如何解决此问题的技巧,以及使softinput Adjustresize整体调整到底部的技巧,都非常受欢迎:)
答案 0 :(得分:0)
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
dialog.setOnShowListener {
Handler().post {
val bottomSheet = (dialog as? BottomSheetDialog)?.findViewById<View>(R.id.design_bottom_sheet) as? FrameLayout
bottomSheet?.let {
BottomSheetBehavior.from(it).state = BottomSheetBehavior.STATE_EXPANDED
}
}
}
return dialog