我发现这段代码创建了一个共享窗口:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ShareActionProvider;
public class AndroidShareActionProviderActivity extends Activity {
private ShareActionProvider myShareActionProvider;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.completed);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
MenuItem item = menu.findItem(R.id.menu_item_share);
myShareActionProvider = (ShareActionProvider)item.getActionProvider();
myShareActionProvider.setShareHistoryFileName(
ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
myShareActionProvider.setShareIntent(createShareIntent());
return true;
}
private Intent createShareIntent() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT,
"http://www.example.com/");
return shareIntent;
}
}
我的问题是,当点击操作栏外的ImageButton时,是否可以打开此共享窗口,如果可能的话,该怎么做?
答案 0 :(得分:0)
this.YOURIMAGEBUTTON.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(createShareIntent()));
}
});