Comments (5)
class BottomSheet : BottomSheetDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return object: BottomSheetDialog(requireContext(), theme) {
override fun onBackPressed() {
// Handle backpress in here
}
}
}
}
from bottomsheet.
Unfortunately there's no easy way to handle this since the sheet is part of the activity's view hierarchy. We handle this in a base activity class, and you can see an example in the sample code's MainActivity
It's not pretty, but unless Activity
has a secret addOnBackPressListener()
API that we're not aware of, I don't see any better solutions. It's mitigated by stuffing it down into a base class. Open to ideas though, any thoughts?
For the record, the system share sheet (and Google Drive I think) get away with this by showing the sheet in a transparent activity on top of the current activity
from bottomsheet.
Of course there is a way to do this, DrawerLayout does. You have to override onKeyDown()
and onKeyUp()
and listen for keyCode == KeyEvent.KEYCODE_BACK
. See http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r1/android/support/v4/widget/DrawerLayout.java#DrawerLayout.onKeyDown%28int%2Candroid.view.KeyEvent%29
from bottomsheet.
Ah true, I always forget it shows up as a KeyEvent. We're going to look into that PR tomorrow, thanks for the suggestion!
from bottomsheet.
@OverRide
public void onBackPressed() {
if (mBottomSheetBehavior.isHideable()) {
super.onBackPressed();
}else {
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
from bottomsheet.
Related Issues (20)
- find crash
- BottomSheet appears in center of page
- Access Buttons in the Bottomsheet
- how to set different style for different status menu item in MenuSheet
- FloatingActionButton overlaps bottomsheet
- There is no way of knowing if the BottomSheet is dismissing HOT 2
- Efficiency vs Google's standard bottom? HOT 1
- Adding All Social Media
- Any scroll-down-picker won't work with bottom sheet
- Have problems with UnityPlayerActivity
- Rounded Corners HOT 1
- MenuSheetView icon
- Bug in height size after expanded list
- BottomSheetFragment expands by himself when I remove elements from the view.
- The width of the bottomsheet on the flat panel device can not occupy the pan
- Can't build project
- Bug: bottom sheet looks almost non-existing when on landscape HOT 1
- Dialog shadow is not appearing in front of status bar.
- java.lang.NullPointerException RecycyclerView
- XPopup is better! https://github.com/li-xiaojun/XPopup
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bottomsheet.