Skip to content

Instantly share code, notes, and snippets.

@yunusemredilber
Created February 15, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yunusemredilber/1de4c88e896c81f87d0ea5a126b81dae to your computer and use it in GitHub Desktop.
Save yunusemredilber/1de4c88e896c81f87d0ea5a126b81dae to your computer and use it in GitHub Desktop.
Android - Material Modal Bottom Sheets
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:id="@+id/my_modal_bottom_sheet_view">
<LinearLayout
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:minHeight="150dp"
android:padding="15dp"
android:orientation="vertical">
<!-- Your Content -->
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
public class LocationPermissionBottomSheet extends BottomSheetDialogFragment {
@Override
public View onCreateView (LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.my_modal_bottom_sheet, container, false);
}
}
/*
* To show:
* MyModalBottomSheet myModalBottomSheet = new MyModalBottomSheet();
* myModalBottomSheet.show(getSupportFragmentManager(), "");
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment