Skip to content

Instantly share code, notes, and snippets.

@ikhlaqmalik13
Created December 6, 2022 17:38
Show Gist options
  • Save ikhlaqmalik13/4c143486f1ff2106b0d88505d6100ec6 to your computer and use it in GitHub Desktop.
Save ikhlaqmalik13/4c143486f1ff2106b0d88505d6100ec6 to your computer and use it in GitHub Desktop.
BottomSheetDialog
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/ll_share"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/share_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:layout_weight="1"
android:text="Share" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_upload"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_baseline_cloud_upload_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:layout_weight="1"
android:text="Upload" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_copy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_baseline_content_copy_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="20dp"
android:layout_weight="1"
android:text="Copy" />
</LinearLayout>
</LinearLayout>
package com.akhteakh.akhteakh.splash
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.akhteakh.akhteakh.databinding.ActivityBottomSheetLearningBinding
import com.akhteakh.akhteakh.databinding.BottomSheetLayoutBinding
import com.google.android.material.bottomsheet.BottomSheetDialog
class BottomSheetLearningActivity : AppCompatActivity() {
private lateinit var binding: ActivityBottomSheetLearningBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityBottomSheetLearningBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.bOpenBottomSheet.setOnClickListener {
val bottomSheetDialog = BottomSheetDialog(this)
val bottomSheetLayoutBinding = BottomSheetLayoutBinding.inflate(layoutInflater)
bottomSheetDialog.setContentView(bottomSheetLayoutBinding.root)
bottomSheetLayoutBinding.llCopy.setOnClickListener {
Toast.makeText(this, "Clicked on copy ", Toast.LENGTH_SHORT).show()
}
bottomSheetLayoutBinding.llShare.setOnClickListener {
Toast.makeText(this, "Clicked on share ", Toast.LENGTH_SHORT).show()
bottomSheetDialog.dismiss()
}
bottomSheetLayoutBinding.llUpload.setOnClickListener {
Toast.makeText(this, "Clicked on Upload ", Toast.LENGTH_SHORT).show()
}
bottomSheetDialog.show()
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".splash.BottomSheetLearningActivity">
<Button
android:id="@+id/b_open_bottom_sheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment