在ActionBarSherlock上分享按钮

时间:2014-04-19 13:54:27

标签: android actionbarsherlock shareactionprovider

我是一个菜鸟开发者......我希望有人可以帮我解决这个问题。 我要在我的操作栏(ABS)中添加分享按钮,但是我遇到了一些问题

我的操作栏菜单XML

<?xml version="1.0" encoding="utf-8"?>

<item android:id="@+id/menu_item_share"
    android:title="Share"
    android:showAsAction="ifRoom"
    android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" />

我的活动

    import android.content.Intent;
    import android.os.Bundle;
    import android.view.KeyEvent;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;

    import com.actionbarsherlock.app.ActionBar;
    import com.actionbarsherlock.app.SherlockActivity;
    import com.actionbarsherlock.view.Menu;
    import com.actionbarsherlock.widget.ShareActionProvider;

    public class DisPlayWebPageActivity extends SherlockActivity {
        WebView webview;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.webview);
            ActionBar actionBar = getSupportActionBar();
            actionBar.setDisplayHomeAsUpEnabled(true);
        ...
        }

    @Override
        public boolean onCreateOptionsMenu(Menu menu) {

            getSupportMenuInflater().inflate(R.menu.actionmenu, menu);

            ShareActionProvider myShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_item_share).getActionProvider();

            Intent myIntent = new Intent();
            myIntent.setAction(Intent.ACTION_SEND);
            myIntent.putExtra(Intent.EXTRA_TEXT, "page_url");
            myIntent.setType("text/plain");

            myShareActionProvider.setShareIntent(myIntent);

            return true;
        }

相关错误

Error:(52, 8) java: com.actionbarsherlock.internal.view.menu.MenuBuilder is not abstract and does not override abstract method getItem(int) in com.actionbarsherlock.view.Menu
Error:(663, 34) java: getItem(int) in com.actionbarsherlock.internal.view.menu.MenuBuilder cannot implement getItem(int) in com.actionbarsherlock.view.Menu
  return type android.view.MenuItem is not compatible with com.actionbarsherlock.view.MenuItem
Error:(605, 34) java: findItem(int) in com.actionbarsherlock.internal.view.menu.MenuBuilder cannot implement findItem(int) in com.actionbarsherlock.view.Menu
  return type android.view.MenuItem is not compatible with com.actionbarsherlock.view.MenuItem
Error:(443, 33) java: addSubMenu(int,int,int,int) in com.actionbarsherlock.internal.view.menu.MenuBuilder cannot implement addSubMenu(int,int,int,int) in com.actionbarsherlock.view.Menu
  return type android.view.SubMenu is not compatible with com.actionbarsherlock.view.SubMenu
Error:(435, 33) java: addSubMenu(int,int,int,java.lang.CharSequence) in com.actionbarsherlock.internal.view.menu.MenuBuilder cannot implement addSubMenu(int,int,int,java.lang.CharSequence) in com.actionbarsherlock.view.Menu
  return type android.view.SubMenu is not compatible with com.actionbarsherlock.view.SubMenu
...

问我是否需要完整的错误日志!

1 个答案:

答案 0 :(得分:6)

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.main, menu);

    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.action_setting:

        Intent next = new Intent(Home.this, Setting.class);
        next.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivityForResult(next, 2);
        return true;

    }

    return true;

}