【发布时间】:2021-08-25 15:06:52
【问题描述】:
我在我的应用程序中实现了一个底页。我使用充气器来显示底页对话框,这是我在 NewSignUpActivity 中显示底页对话框的代码。
class NewSignUpActivity : AppCompatActivity() {
private lateinit var btnBottomSheet: RelativeLayout
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_rider_or_bike)
btnBottomSheet = findViewById(R.id.riderBtn)
val bottomSheetCallback = object : BottomSheetBehavior.BottomSheetCallback(){
override fun onStateChanged(bottomSheet: View, newState: Int) {}
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
}
val bottomSheetView = layoutInflater.inflate(R.layout.layout_bottom_sheet, null)
val bottomSheetDialog = BottomSheetDialog(this)
bottomSheetDialog.setContentView(bottomSheetView)
val bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetView.parent as View)
bottomSheetBehavior.setBottomSheetCallback(bottomSheetCallback)
btnBottomSheet.setOnClickListener {
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
bottomSheetDialog.show()
}
}
}
这是它在视图中的样子。
如您所见,当我单击“是”按钮后,我想在底部表单上导航到另一个布局活动,我该怎么做?我对使用 Kotlin 进行 Android 开发非常陌生。
已编辑:为bottomsheet 对话框添加了我的 XML 文件,请参见下文。_ 文件名是 layout_bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layoutBtmSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/rectangle"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/_20sdp"
android:layout_marginRight="@dimen/_15sdp"
android:layout_marginBottom="@dimen/_30sdp"
android:src="@drawable/close_black" />
</RelativeLayout>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:background="@drawable/bgwhite"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="@+id/ll_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_30sdp"
android:layout_marginTop="@dimen/_20sdp"
android:layout_marginRight="@dimen/_10sdp"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/outline_sports_motorsports_black_48"
tools:layout_editor_absoluteX="3dp"
tools:layout_editor_absoluteY="3dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_10sdp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toRightOf="@+id/ll_one"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_there_partner_rider"
android:textSize="18sp"
android:textStyle="bold" />
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/_5sdp"
android:text="@string/lorem_ipsum" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout">
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_100sdp"
android:layout_marginBottom="@dimen/_10sdp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.49"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout3"
app:layout_constraintVertical_bias="0.678">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/noBtn"
android:layout_width="169dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/bgbtn1"
android:radius="@dimen/_50sdp"
android:text="No" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/yellowBtn"
android:layout_width="169dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textColor="@color/white"
android:background="@drawable/bgbtno"
android:text="@string/yes" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:textColor="@color/reply_black_800"
android:text="@string/are_you_using_your_own_motorcycle"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout"
app:layout_constraintVertical_bias="0.074" />
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
你能显示你的底部工作表对话框的xml代码吗?
-
我在上面编辑了我的问题,请查看我的 XML 文件
标签: java android kotlin android-bottomsheetdialog