Bottom stock list in Android

When sharing data in an Android app, I've seen several apps use a bottom sheet (like Google 2015 I / O) to tell apps to take an action, rather than a standard dialog box that includes apps to handle your intent.

For example:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TITLE, "Some title..");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Some text");
startActivity(Intent.createChooser(shareIntent, "Share via.."));

      

doesn't do the trick, since the OS version chooses to display the selection.

Any way to modify this code to get a generic shot based on stuff https://www.google.com/design/spec/components/bottom-sheets.html#bottom-sheets-content enter image description here

Does anyone know of third party libraries to only do this on older API versions?

I found https://github.com/soarcn/BottomSheet

but this only allows me to create a menu from the bottom sheet. My guess is that in reality I can find all applications that can do the actions I am trying to do and manually add menu items on top of this library, but I was hoping for something a little simpler as this is not a violation of the function.

+3


source to share


3 answers


Here's the exact bottom sheet on a Nexus 5 running Android 6.0.

This may be different in older or modified versions of Android. (i.e. Samsung devices, etc.)


code



Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Check out this dope website! - http://www.mikemilla.com/"); // Simple text and URL to share
sendIntent.setType("text/plain");
this.startActivity(sendIntent);

      


Result

enter image description here

+12


source


Our BottomSheet implementation has a generic component that you can use so that you can specify an intent / filter / etc for the sheet and it will behave similarly to the Lollipop version of the system



https://github.com/flipboard/bottomsheet

+3


source


I used a combination of the two answers above: Using inline bottom sheet in M ​​+ and https://github.com/flipboard/bottomsheet for API levels below M.I prefer the inline bottom sheet that Android provides for sharing because it is partially slides, and then the user can slide over it completely. The third library Bottom Sheet provides backward compatibility without folding it so you can quickly drop it. However, I prefer the built-in one.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  Intent sendIntent = new Intent();
  sendIntent.setAction(Intent.ACTION_SEND);
  sendIntent.putExtra(Intent.EXTRA_TEXT, "Content"); 
  sendIntent.setType("text/plain");
  this.startActivity(sendIntent);
}else {
  Intent intent = new Intent(Intent.ACTION_SEND);
  intent.setType("text/*");
  intent.putExtra(Intent.EXTRA_TEXT, "Content");
  BottomSheet share = BottomSheet.createShareBottomSheet(MainActivity.this, intent, "Title");
  share.show();
}

      

+3


source







All Articles