Gabriel Ittner
Gabriel Ittner

Reputation: 1162

intent.createChooser always displays dark dialog

My app uses a light theme, but the dialog created with Intent.createChooser() always is dark. I wrote a test app, which just displays the dialog:

public class AsdActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, new String[]{"abc"});
        intent.putExtra(Intent.EXTRA_TEXT, "blah");

        startActivity(Intent.createChooser(intent, "aaa"));         
    }
}

I tried Theme.Light and Theme.Holo.Light, but it just doesn't work.

How do I make the Chooser use a light theme?

Upvotes: 2

Views: 2019

Answers (2)

Sparky
Sparky

Reputation: 8477

I suspect that you can't control the color of the Chooser because it belongs to the system, not your app. However, I don't see any reason why you couldn't implement your own Chooser in an AlertDialog that follows your theme. Here's a code snippet that fetches a list that you can use to populate the dialog:

    PackageManager packageManager = getPackageManager();

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, new String[] { "abc" });
intent.putExtra(Intent.EXTRA_TEXT, "blah");

List<ResolveInfo> list = packageManager
    .queryIntentActivities(intent, 0);

if (list.size() > 0) {
    StringBuilder outStr = new StringBuilder("Available receivers:");
    for (ResolveInfo resolveInfo : list) {
        outStr.append("\n");
        outStr.append(resolveInfo.loadLabel(packageManager));
    }
    tv.setText(outStr);
} else {
    tv.setText("No available receivers!");
}

Upvotes: 1

Jan Knotek
Jan Knotek

Reputation: 1

Have you tried to use some Intent constructor, which uses Context? It could be the way, how to pass theme to the dialog.

Upvotes: 0

Related Questions