Dynamic colours in an app - android

I have colors of text and button come dynamic form backend,
I need to change this color of text dynamically when change happens in backend all at time.
I could make it manual
textView.setTextColor(getResources().getColor(R.color.text_color));
Is there a way to change group of text color dynamically or must set every text color manually in code?
I searched for how to change theme colors dynamically at run time and i found this answer this answer.
But I also search again and I found this github
but it doesn't work on Android Marshmallow (6.0+) and it's use is discouraged! as he say.
Is there any lib or method to change the theme on runtime?

So far it's impossible and not viable because of themes are immutable.
GreenMatter becomes outdated so regretfully the answer of your question is No way.
More precisely, the color overriding at runtime is not working. There is no fix found at the moment. The future of this feature is uncertain.

Related

android support lib 23.1.1 changes floating label color on setError()

is there a way to change the color of 'Password'? Basically, I prefer what support lib 23.1.0 had. I have a page that has multiple TextInputLayouts, and it would be hard to read if both hint and error are in red. please see the screenshot below.
there are a few fixes I want in 23.1.1, so please don't ask me to stay with 23.1.0. Thanks for all the help!!
Since it is a change in library it would be difficult to manipulate it. Android has decided to go that way (changing the label color along with the hint's color) and will become a standard soon and users will get familiar with it as time passes by. Not much we can do about it, but adhere, as always.
Workaround:
Don't set the Labels field on the TextInputLayouts. keep it blank and put another TextView just above it with the desired color and properly align it. That will not change, of course.
As per my comment below, you could also try this:
Hint color wont change. Just checked. So you may want to remove label and just add hint as android:hint="Enter password". The word Password in your screenshot is set in the Label and not as a hint.

Modify Android Theme Programmatically

A similar question to this has been asked many times; however, an answer has not been given that addresses my situation. I need to dynamically change an application's theme based on color values that are being returned from an API call. I then need to change the theme colors of the app based on the values returned. Therefore, I have no way of saving the colors in a style XML file. Can this be done?
I have a base activity, and my plan is to set the app theme from there for all the activities.
Unfortunately, I did not find an easy way to do this. I created a ThemeColor class which holds all the colors returned by the API. Then for each activity I have to go through every widget and style it.
Example:
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(themeColor.getActionBarColor)));
this.getWindow().getDecorView().setBackgroundColor(Color.parseColor(themeColor.getBackgroundColor()));
etc
I was not able to locate a simple way to resolve this issue either. By creating a ThemeColor class that holds all the colors returned from the API. Next for each activity I needed to address each widget separately as well as style it.

Which is the preferred method when using/calling colors in android?

E.G. #FFFFFFFF OR color/white
Is there any difference/affect in performance on color redraws? Pros/Cons ?
I have asked a few android theme developers and some say that using the #FFFFFFFF recommended as its basically telling it how it is, rather than using the color/white which is to call from another location.
Though I have asked then why in say for example Android Framework/res/values/colors, both formats are being used ?
Is there any difference/affect in performance on color redraws?
Pros/Cons ?
not really.
#color/white
retrieve an entry in your colors.xml file, that contains the colours in the hex format.
#android:color/
retrieve an entry in the colors.xml file provided by the framework
Performance reasons, no.
But, you will likely want a combination of the two. You will define color/white in your styles and in the styles you will set color/white to #FFFFFFFF.
The reason for this is that you can reference the same white color that you defined in the styles everywhere in your app. So if (when?) the day comes that your designer says "I don't want pure white anymore, I want a creamy off-white" you can just change the color in one place and you're done. And if the name is no longer representative of what it is, you can do a global rename with just a few keystrokes.
#FFFFFFFF will make you have control over it.
color/white will have android/samsung/htc/lg control over it; they can override it with somewhat white or greyish in framework.
So, it depends if you want it to be in sync with the white globally in the users framework or not.

Updating Android EditText's hint on focus change using XML only

I read with interest user sunit's answer to this question about updating an EditText's hint but have been unable to find any documentation on using the method that I presume he appears to describe there: using the <selector> element in an XML layout to dynamically adjust attributes of an EditText at runtime when the element is focused/unfocused.
In my case I am actually more interested in adjusting the android:inputType element (because the hint disappears for me when the inputType is specified) but adjusting the hint would work just as well.
To be clear I know how to make this change in Java code--I'm trying to find out if there is a way to specify the behavior in XML. Thanks!
I'm afraid it isn't yet possible. <selector> is only valid to be applied in making state lists out of Drawable and Color resources, it does not yet work for Strings.
With regards to your mention of adjusting android:inputType to make the hint disappear, this is actually a known Android bug that will eventually be fixed in later versions so I wouldn't recommend building your code around this functionality as it will break when they fix it:
http://code.google.com/p/android/issues/detail?id=13895
Since you mentioned that you already know how to do this in the Java code, I won't point out how to call setHint() from within a OnFocusChangeListener ;)
Cheers.

Android easy switch color-scheme of application

How would you implement different color themes in your app?
All I can see now is plain set color onCreate every activity and control...
Also, how would you store different color schemes in xml?
Just an entries of with different names?
Thank you!
Use custom Themes, which are declared in XML. They are very similar to CSS, if you've used them before.
EDIT:
Here's a better example of changing the theme at run time

Categories

Resources