我第一次使用上下文操作栏。当我单击我的 ListView 的项目时,我希望能够以某种方式共享该项目(whatsapp/mail/gmail/drive 等)。我正在尝试使用这种方法,但没有效果:菜单布局:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/shareButton"
android:actionProviderClass="android.widget.ShareActionProvider"
android:title="@string/share"
android:showAsAction="always"/>
</menu>
上下文操作栏类:
public class CABMode implements ActionMode.Callback {
private ShareActionProvider mshare;
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.cab, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// don't need to do anything
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
mshare = (ShareActionProvider) item.getActionProvider();
mshare.setShareIntent(Share());
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
Mode = null;
}
public Intent Share() {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Share");
return intent;
}
}
好吧,当我长按时它会很好地打开上下文操作栏,但是操作栏中的共享按钮不起作用。当我说“不起作用”时,我的意思是这似乎不可点击。当我单击该项目时,没有任何效果。什么都没有出现。我想要的是打开多种共享方式。谢谢