Styling the Share Action Provider in Android
Asked Answered
H

3

6

enter image description here

Here is how I share the content through Share Action Provider:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
                    "Check the Link  : " + url);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share with"));

I want to style the share with window. I want to change the text color and highlighter line color from default blue color to my custom color. I am using Holo light theme. I don't know how to style those elements. Can anyone point out a reference to do that?

Is there a way to access attributes of android.widget.ShareActionProvider through styling?

Hamhung answered 9/1, 2013 at 3:24 Comment(1)
Can you be a bit clear on what you want exactly? It would be better if you could show your previous code and effort.Stollings
A
1

As far as I know, you cannot style the chooser dialog. It is a system-level actvity, and uses the default system theme.

Ardel answered 9/1, 2013 at 3:49 Comment(1)
okay. Where can I find the style elements for android.widget.ShareActionProvider? Is it possible?Hamhung
M
2

I don't know how to style the dialog, i have seen different layouts in different devices. But you can use PackageManager.queryIntentActivities(Intent intent, int flag) to get all activities that could handle this intent. And use the list data to create your own chooser.

EDIT: a demo

    final Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://www.google.com"));
    PackageManager pm = getPackageManager();
    final List<ResolveInfo> infos = pm.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    CharSequence[] names = new CharSequence[infos.size()];
    for (int i = 0; i < infos.size(); i++) {
        names[i] = infos.get(i).loadLabel(pm);
    }
    new AlertDialog.Builder(this).setItems(names,
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ResolveInfo info = infos.get(which);
                    intent.setClassName(info.activityInfo.packageName,
                            info.activityInfo.name);
                    startActivity(intent);
                }
            }).show();
Modular answered 9/1, 2013 at 3:52 Comment(2)
I cannot find a reference, so i write a demo for you.Modular
Thanks @faylon. Good piece of work. I made some design changes to make that available to my application theme.Fanchon
A
1

As far as I know, you cannot style the chooser dialog. It is a system-level actvity, and uses the default system theme.

Ardel answered 9/1, 2013 at 3:49 Comment(1)
okay. Where can I find the style elements for android.widget.ShareActionProvider? Is it possible?Hamhung
H
0

You can also use like this

        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(android.content.Intent.EXTRA_SUBJECT,getString(R.string.app_name));
        intent.putExtra(android.content.Intent.EXTRA_TEXT,getString(R.string.tell_your_frnd));
        PackageManager pm = getPackageManager();
        final List<ResolveInfo> infos = pm.queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        name = new String[infos.size()];
        image=new Drawable[infos.size()];
        for (int i = 0; i < infos.size(); i++) 
        {
            name[i] = (String) infos.get(i).loadLabel(pm);
            image[i]=infos.get(i).loadIcon(pm);
        }


        CustomGrid adapter = new CustomGrid(ShareActivity.this,name,image);
        mGridView.setAdapter(adapter);

        mGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,int position, long id) 
        {

            ResolveInfo info = infos.get(position);

            intent.setClassName(info.activityInfo.packageName,
                    info.activityInfo.name);
            startActivity(intent);
        }
    });
Hebdomadary answered 1/9, 2015 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.