Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a theme/style when using startActivity()

Simple question:

I am using PICK_CONTACT in my Android 3.0 application. The issue is that the contact app has a light theme while my app uses a dark one.

So the question is:

Is there a way to set a style/theme when using startActivity()?

If I am creating my own library and I want the user to be able to use customize styles, I will need to receive something in the intent? Is there a better way to solve this?

like image 999
Macarse Avatar asked Apr 29 '11 12:04

Macarse


People also ask

What is startActivity ()?

To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.

How do you change themes on Android?

Navigate to the app > res > values > themes > themes. xml for light mode and add the below code to it.


2 Answers

Is there a way to set a style/theme when using startActivity()?

No. You have no right to mess with other apps' user interfaces, any more than they have a right to mess with yours.

In the case of PICK_CONTACT, if you are willing to have the READ_CONTACTS permission, there is nothing stopping you from writing your own contact picker activity, themed as you wish.

If I am creating my own library and I want the user to be able to use customize styles, I will need to receive something in the intent?

Since there is no setStyle() method, dynamically changing an activity's style seems troublesome.

If your library will be shipped as an Android library project, you can provide theme resources and guidance for developers who, when adding your activities to their manifest, can choose which theme to use at compile time.

like image 189
CommonsWare Avatar answered Sep 19 '22 22:09

CommonsWare


No.

In general there is no standard method of specifying the theme/style an Activity should launch with: your idea (putting something in the Intent) would actually be an excellent way of doing it, but once again it isn't standard.

Wandering through the standard Contacts app source (https://android.googlesource.com/platform/packages/apps/Contacts ) there is no way to specify the theme in any of the Activity classes that PICK_CONTACT would invoke.

Your best bet would be to build a custom Contact picker and use the content provider. You'd need to ask for permissions and it would be a bit messier but that appears to be the only way to get what you want.

like image 31
Femi Avatar answered Sep 21 '22 22:09

Femi