ABS - ShareActionProvider: How to remove icon on right hand side

瀏覽次數:2,559 次
跳到第一則未讀訊息

tiptopjat

未讀,
2012年6月16日 晚上7:26:462012/6/16
收件者:actionba...@googlegroups.com
I have implemented ShareActionProvider in my ABS.

When a user selects an app to share content with, eg Twitter, the actionbar displays a Twitter icon next to the Share button.

Does anybody know how to disable this?

Sven Meier

未讀,
2012年6月17日 清晨5:06:022012/6/17
收件者:actionba...@googlegroups.com
Hi,

this is no ABS question but here's a solution anyway:

Implement OnShareTargetSelectedListener and set it on the
ShareActionProvider:

@Override
public boolean onShareTargetSelected(ShareActionProvider source,
Intent intent) {

context.startActivity(intent);

// started activity ourself to prevent search history
return true;
}

Now the selected share action will no longer appear in the search
history on the actionbar.

Hope this helps
Sven

tiptopjat

未讀,
2012年6月17日 清晨6:53:402012/6/17
收件者:actionba...@googlegroups.com
Thanks for sharing this solution, but I can't get it to work.

Here's my code, should I modify anything in OnCreateOptionsMenu()?



public class MainActivity extends SherlockListActivity implements OnShareTargetSelectedListener {

        public onCreate....{}

        @Override
public boolean onCreateOptionsMenu(Menu menu)  {
// Inflate your menu.
getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);

// Set file with share history to the provider and set the share intent.
MenuItem actionItem = menu
.findItem(R.id.menu_item_share_action_provider_action_bar);
ShareActionProvider actionProvider = (ShareActionProvider) actionItem
.getActionProvider();
actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);

//actionProvider.setShareIntent(createShareIntent());

return true;
}
public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) {
// TODO Auto-generated method stub
this.startActivity(createShareIntent()); 

                 return true; 
}

private Intent createShareIntent() {
// Creates intent to share
intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT,

return intent;
}

tiptopjat

未讀,
2012年6月17日 上午8:59:592012/6/17
收件者:actionba...@googlegroups.com
The main reason I would like to remove the application icon is because the icons have a grey border, which doesn't match my black actionbar. (http://imageshack.us/photo/my-images/155/20120617130029.jpg/). Do you know how I can change this from black to grey? I would be happy to keep the app icon on the action bar if I could change the grey colour.


On Sunday, June 17, 2012 10:06:02 AM UTC+1, Sven Meier wrote:

Sven Meier

未讀,
2012年6月17日 上午9:42:372012/6/17
收件者:actionba...@googlegroups.com
You have to set your listener on the action provider:

    actionProvider.setOnShareTargetSelectedListener(this);

Sven

tiptopjat

未讀,
2012年6月17日 上午10:03:052012/6/17
收件者:actionba...@googlegroups.com
That works perfectly! Thank you. 

Chris Ian Fiel

未讀,
2013年2月8日 凌晨4:06:122013/2/8
收件者:actionba...@googlegroups.com

I tried this solution but it does not work. the button cannot be press this is my code below. any idea what I am missing?

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

MenuItem actionItem = menu.findItem(R.id.share);
ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
actionProvider.setOnShareTargetSelectedListener(this);

return true;
}

@Override 
        public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { 
               this.startActivity(createShareIntent()); 
        return true; 

        private Intent createShareIntent() {
       File file = new File(SharedPrefsConfig.SD_TONES+name+".mp3");
           Intent shareIntent = new Intent(Intent.ACTION_SEND);
           shareIntent.setType("audio/*");
           Uri uri =  Uri.fromFile(file);
           shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        return shareIntent;

තරිඳු ගුණවර්ධන

未讀,
2013年8月18日 凌晨4:06:222013/8/18
收件者:actionba...@googlegroups.com
Set the intent to your provider.
ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
actionProvider.setShareIntent(createShareIntent());
...

Then,
@Override 
        public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) { 
               this.startActivity(intent); 
        return true; 

Prasanna Gunasekeran

未讀,
2014年6月2日 凌晨3:18:002014/6/2
收件者:actionba...@googlegroups.com
This solution is not at all woorking cant able to clik on share icon...
Anybody know the exact solution
回覆所有人
回覆作者
轉寄
0 則新訊息