Android: SharingActionView on swipe from bottom -
i share data other apps, don't want standard popup appears bottom tool bar; want kind of view:
i followed official document: https://developer.android.com/training/sharing/shareaction.html
so there native component in android sdk? or there library that?
thank guys!
you can :
first create menu item :
<menu 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" tools:context="com.example.rashish.myapplication.mainactivity"> <item android:id="@+id/action_share" android:orderincategory="100" android:title="@string/action_settings" android:icon="@android:drawable/ic_menu_share" app:showasaction="always" /> </menu>
then create method show intent chooser dialog, :
private void share() { string texttoshare = "hello"; intent sharingintent = new intent(intent.action_send); // set type here i.e, text/image/ etc. sharingintent.settype("text/plain"); sharingintent.putextra(intent.extra_subject, "subject here"); sharingintent.putextra(intent.extra_text, texttoshare); startactivity(intent.createchooser(sharingintent, "share via")); }
then in onoptionsitemselected
method, call function when menu item clicked :
@override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. int id = item.getitemid(); if (id == r.id.action_share) { share(); return true; } return super.onoptionsitemselected(item); }
also make sure you've overriden oncreateoptionsmenu
in activity :
@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; }
here's output :
Comments
Post a Comment