Reputation: 33
I am working on an android webview app, i have added share action on action bar which works fine when showAsAction is 'never, but stop working as soon as i change it to 'always' or 'ifRoom'` my code is:
private ShareActionProvider mShareActionProvider;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public final boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_share:
shareURL();
}
return super.onOptionsItemSelected(item);
}
private void shareURL() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl());
startActivity(Intent.createChooser(shareIntent, "Share This!"));
}
if someone could help, thank you.
Upvotes: 0
Views: 305
Reputation: 929
Remove the android:actionProviderClass="android.widget.ShareActionProvider"
and add the android:icon="@drawable/image-name"
Upvotes: 1
Reputation: 900
Are you sure you actually have space to display it?
You could try disabling the title to see is that created enough room:
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Update:
Can you try using:
public void setOnMenuItemClickListener (Toolbar.OnMenuItemClickListener listener)
I believe the toolbar has a separate listener than the dropdown menu.
The code could look something like:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar tb = (Toolbar) findViewById(R.id.toolbar_id);
tb.inflateMenu(R.menu.menu);
tb.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// Menu item should be returned here (the one you tap on the toolbar)
return false;
}
});
}
Upvotes: 0