Android shared Action

Source: Internet
Author: User

Using ActionProvider in Android4.0 (API leverl 14) makes it easier to implement a user-friendly and efficient shared Action in the ActionBar. Once an ActionProvider is appended to the Intent ActionProvider menu, you only need to provide a shared Intent, and the rest of the work is done by it. Note: ActionProvider can only be used in API lever 14 and later versions. Update menu Declaration: to use javasactionprovider, we must first define the following content. Define the android: actionProviderClass attribute in the corresponding menu resource file <itme>. <Menu xmlns: android = "http://schemas.android.com/apk/res/android"> <item android: id = "@ + id/menu_item_share" android: showAsAction = "ifRoom" android: title = "Share" android: actionProviderClass = "android. widget. using actionprovider "/>... </menu> In addition, you need to provide the provider with the information you want to share. Set the sharing Intent: to implement the sharing actionprovider function, we must implement a sharing Intent. This Intent not only contains the content required by other Intent to transmit content to other applications, such as ACTION_SEND and extras, but also the following content. When filling your menu resources in your Activity or Fragment, you need to find MenuItem, use MenuItem. getActionProvider to get the Intent actionprovider instance, and use setintent provider to update the shared Intent. Private sector actionprovider mpipeline actionprovider ;... @ Overridepublic boolean onCreateOptionsMenu (Menu menu) {// Inflate menu resource file. getMenuInflater (). inflate (R. menu. performance_menu, menu); // Locate MenuItem with your actionprovider MenuItem item = menu. findItem (R. id. menu_item_share); // Fetch and store your actionprovider m?actionprovider = (?actionprovider) item. getActionProvider (); // Return true to display menu return true;} // Call to update the share intentprivate void setincluintent (Intent incluintent) {if (m?actionprovider! = Null) {m1_actionprovider. setincluintent (incluintent );}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.