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?
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.
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.
Related
I'm having hard times trying to implement a preference who switch the application theme.
Normally I would be able to do it with XML but with Jetpack Compose I saw that the best practice is to use DataStore (https://developer.android.com/topic/libraries/architecture/datastore)
Someone please, can explain me from scratch how to store a preference and change the whole application theme when the user click on a button for example?
Thank you
I believe that the DataStore documentation already explains in great detail how it works...
Talking about Compose we have the isSystemInDarkTheme function which brings up the current theme of the user's android system (which can be seen in Theme.kt inside the ui package that Android Studio automatically creates in a Compose project).
What needs to be done is whenever you open the app, check if the user has chosen to change the theme manually in your app through a function that accesses the DataStore, in other words, provide a Flow<Boolean?>, with a logic like if null the user has not changed the theme on your app, so you follow with the android system and if have the boolean, pass and apply to the MaterialTheme of Compose.
And you also need to create a function that sends a boolean to the DataStore regarding the theme change on the app.
Here is a repository with example code allowing the user to change the theme between dark and light and saving the option in the DataStore. And here is an article with theoretical and practical explanation about themes in Compose which I think may contribute to the clarification.
I am working on an Android library which contains a few activities and fragments. Aim is to make it plug and play sorts that should easily fit-in in any app. However since we provide theme to every activity and not the complete application I am unsure on how to go about things. For eg: color_primary, color_accent etc are all dependent on app. These need to be set in theme dynamically. I can get these colors from app via a communicator or I can setup backend to send me these colors based on what app is using my library.
However, I am unable to figure out how to set these colors on the fly. Will it be possible to create a theme programatically and then set to activity? Or, is there any other approach to solve my usecase?
I'm trying to figure out (if it's even possible) to override the behavior of the built in ICS launcher folders.
I have a specific and small change I'd like to add (simply add a button on the top to sort alphabetically to start with). From looking at the source for Launcher2 add the behavior should be easy enough, but I can't seem to figure out way to hook into the launcher and override specific bits.
I would hazard to guess that the correct approach is that you have to implement a full custom launcher (by altering the class I'm interested in changing and recompiling Launcher2) and that what I'm hoping to do isn't possible. Android/Java is not my day job so I'm hoping there might be a way that I'm not seeing that a more experienced developer is aware of.
In short is/how can I implement a custom subclass of com.android.Launcher2.Folder and have that used instead? Preferably with just a drop in app rather than having to completely override the normal ICS launcher app.
I'm trying to figure out (if it's even possible) to override the behavior of the built in ICS launcher folders.
No, sorry.
I would hazard to guess that the correct approach is that you have to implement a full custom launcher (by altering the class I'm interested in changing and recompiling Launcher2) and that what I'm hoping to do isn't possible.
Correct. Beyond that, you cannot simply reuse their code, as packages have to be unique in Android devices.
how can I implement a custom subclass of com.android.Launcher2.Folder and have that used instead?
Completely rebuild the firmware that contains the modified class, then use that modified firmware on your device. Or, refactor the entire home screen app into your own package, get it building as a standalone app (which may not be easy), and then add in your change.
Far simpler would be for you to make your own app widget that implements some sort of folder construct. That would not "override the behavior of the built in ICS launcher folders", but it could give you the functionality you seek.
I have created an Android app using the standard controls available. It seems that most apps on the market have their own set of controls. It generally looks much better that the standard controls. How do I create better looking control? Can I just apply a theme or should I overwrite the onDraw method? For instance, there is a problem with the default android spinner control details here .
adding custom images is the best way to have more eye-catching GUI, use colorful & meaningful images to your application to appeal users. Custom theme's and styles are helpful too.....
You can apply different themes and styles on the one hand or work with 9patch-drawables - have a look here for details and examples
I have an idea to create Themes for Android Mobile. But I have no knowledge of how to do this. I would need to know about the following things:
What is the file format of a theme for Android?
What kind of things I want to handle to change the themes (i.e background, directory window, wallpaper, icon selector style, etc.)
How to start to learn about this
Sites and tutorials for beginners
Sample applications and code
If you passed by information about anything above, please share with me. It would be helpful.
Thanks.
I would start with Google's page on Styles and Themes. Many of your questions are answered there.
http://developer.android.com/guide/topics/ui/themes.html
Here's a simple tutorial:
http://developerlife.com/tutorials/?p=309
EDIT:
If you are talking about themes for the phone instead of the app, you can create themes for specific home screen replacements such as aHome. I'm sure if you look around their site you can see how to create a theme for their app.
There are also sites like Android Themes, but they require that you have rooted your phone and have installed a custom ROM such as those by Cyanogen.
Perhaps you could also write your own custom home screen.