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?
Related
I have to create 2 application with almost the same design. But the backend i mean the way i receive data and i make request to my api is not the same. And there are also minor design such as color or bouton placement...
So i wanted to know if it's possible to create and app template i was thinking of creating a library module such as aar that would hold all the design then i would import it in both my application ?
But if i do that, is there a way to to update the design of the library within the app for exemple i assume that i want to change some color i could do it programmatically, but what happen if i want to change some button position or add rounder corner ? Do i have to provide methodes in my library to handle all those cases ? or is there a way to handle those within the app, meaning that the app could change some design of the library it self ?
In the end would like to have the logic in my app then give all information to the template library to render the design. So i would like to know if there is a way to implement such thing and what are the best practices to do it.
I have in my projects two ways.
Library, as you mention. I use it when there are routines that are common to several projects. It is possible to change color patterns and some style details. But it is often plastered.
Flavors - Build Variants https://developer.android.com/studio/build/build-variants
With build variants you can create one project/app with two versions, chandind only wat you need. This option is very good when you want to change color, endpoint, style, show or hide some system functionality. I use it and it's very good.
It's traditional to use theme for the whole application. Also we can use multiple themes if it's needed.
My question is what is the maximum number of themes allowed to be used in a single android application ?
Is there any performance issue or any known issue that I need to be concerned about if I use large number of themes defined in styles.xml and define for each activities in my android app.
Theme is used for Views, views are obtained by Activity, Fragment, Dialog etc...
You can use multiple themes for any layout or views according to your requirement, There is no limitation of using themes for any views.
I think there will be not any kind of performance issue by using separate themes for each Activity, because there is not mentioned on developer site.
I have a react native application called A, now I want create another application very similar to A, I only need change some colours the rest of the code is exactly the same. One option could be create a new application B and copy all the code from A and change the hard coded colours, obviously it doesn't look very clever because now I have to maintain two different applications.
There are any way to load the colours information from a theme file and then when I start the application determinate what file the application should use?
You can do it using product flavors.
Take a look at the docs:
http://developer.android.com/tools/building/configuring-gradle.html
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
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.