(1) I am confused with the themes in android.
For example android:Theme.Material.Light and Theme.AppCompat.Light.
Also Holo light and dark themes.
I don't understand when to use what. Can someone explain me the differences of these android themes?
Need a good explanation about these themes so that I can understand how this works in my style.xml.
(2) why there are prefixed and non prefixed attributes in style tags.
<item name="colorPrimary">#3F51B5</item>
<item name="android:colorPrimary">#3F51B5</item>
when to use prefix?
Can someone explain this?
The important thing to note about these themes is that not every version of Android will support them. Thus, you may want to use different themes depending on which version of Android your application gets installed on. Derek Banas had a great video on styles and themes:
https://www.youtube.com/watch?v=W3xHIN15hP8
I'm not the most knowledgeable about styles, but I'll give it a shot. I believe that "android:colorPrimary" is used when you are overriding an attribute in an already defined style. I'm not the most knowledgeable about styles so I will lead you to the documentation page that I found that seems to cover this topic fairly well:
http://developer.android.com/guide/topics/ui/themes.html
Here are some references for further reading
https://plus.google.com/+AndroidDevelopers/posts/JXHKyhsWHAH
https://plus.google.com/+AndroidDevelopers/posts/AV2ooBWY1iy
Related
I've added dark theme support for my application using 2 different themes declared in styles.xml.
On official android developer site:
In order to support Dark theme, you must set your app's theme (usually
found in res/values/styles.xml) to inherit from a DayNight theme
and this is what I've done. I've also created colors-night.xml to avoid modifying colors that cannot be modified in styles.xml by coding and this works too: when dark mode is activated from device system, colors changes automatically.
At this point, I was wondering which is the best way to implements dark theme: creating 2 different themes, using colors-night (and drawable-night) or a combination of these 2 ways?
First up is the youtube video below pretty much tells you what the current best practices are with regards to theming.
https://www.youtube.com/watch?v=Owkf8DhAOSo
They talked about splitting your styles into
themes.xml -> theme related styles
styles.xml -> component related styles
type.xml -> text appearances styles
All your colors should then be in one colors.xml which lives in values.
You will then have the following structure:
values/themes.xml
values/colors.xml
values/type.xml
values/styles.xml
values-night/themes.xml
In practice, I find that it is still hard to contain all the colors in just one colors.xml. I still create values-night/colors.xml as some colors don't necessarily fall into a style.
See this in practice in this repo. Observer that Google themselves didn't follow their point on just using one colors.xml.
https://github.com/material-components/material-components-android/tree/master/material-theme-builder
I'm trying to understand the principles of using Material Design a bit better (I'm new to this area and have been reading documentations and tutorials, but the subject is still a bit vague to me), and I'll be glad for some help. What I've tried so far is having 2 folders (values and values-21) with a styles.xml file per each of them -
values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
values-v21/styles.xml:
<style name="AppTheme" parent="android:Theme.Material.NoActionBar"></style>
The problem begins where I try to use activities that inherit from AppCompatActivity (To my understanding, that's what I need to do in order to support backwards compatibility on devices before Lollipop for things such as Material Design? Am I correct? More info here would be great). If I do that, the app won't run on devices that have API 21 or above, since "AppTheme" has to inherit from AppCompat.
What I can do to solve that, is to create a base theme that inherits from AppCompat , and then make the style in both files to inherit from that base theme... But then I'm not inheriting from Material anymore.... which brings me to the question(s) -
Is Material Design just a given theme? And if so, how do I solve my problem? And what does using AppCompatActivity exactly accomplish here? Or is Material Design essentially just a set of rules and principles I'm supposed to follow? And if so, why do we need Theme.Material.* at all? I'll be glad for any extra info anyone can give me on the subject.
Thanks!
The whole point of AppCompat is that you only need one theme (you don't need a separate one in values-v21) and it will be the same experience on all devices.
Theme.AppCompat already extends android:Theme.Material on API 21+ - it is just handling all of the version checking for you.
I'm trying to understand the principles of using Material Design a bit better (I'm new to this area and have been reading documentations and tutorials, but the subject is still a bit vague to me), and I'll be glad for some help. What I've tried so far is having 2 folders (values and values-21) with a styles.xml file per each of them -
values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"></style>
values-v21/styles.xml:
<style name="AppTheme" parent="android:Theme.Material.NoActionBar"></style>
The problem begins where I try to use activities that inherit from AppCompatActivity (To my understanding, that's what I need to do in order to support backwards compatibility on devices before Lollipop for things such as Material Design? Am I correct? More info here would be great). If I do that, the app won't run on devices that have API 21 or above, since "AppTheme" has to inherit from AppCompat.
What I can do to solve that, is to create a base theme that inherits from AppCompat , and then make the style in both files to inherit from that base theme... But then I'm not inheriting from Material anymore.... which brings me to the question(s) -
Is Material Design just a given theme? And if so, how do I solve my problem? And what does using AppCompatActivity exactly accomplish here? Or is Material Design essentially just a set of rules and principles I'm supposed to follow? And if so, why do we need Theme.Material.* at all? I'll be glad for any extra info anyone can give me on the subject.
Thanks!
The whole point of AppCompat is that you only need one theme (you don't need a separate one in values-v21) and it will be the same experience on all devices.
Theme.AppCompat already extends android:Theme.Material on API 21+ - it is just handling all of the version checking for you.
I'm quite confused about how styling in appcompat library works.
According to here:
We now use the support implementation of Toolbar/ActionBar on all
platforms meaning that we no longer read any android: attributes
related to the action bar.
For apps which already have existing appcompat setups, this means that
you should remove your v14+ themes which re-set the same values in the
android namespace. Please note, this is ONLY applicable for
styles/widgets which affect the action bar.
For most apps, you now only need one theme declaration, in values/
So here is my question:
If I want to use material design ActionBar in API 14+, I can just use ActionBar/Toolbar provided in appcompat_v7 and style it in the common value/ folder with the "android:" namespace removed ? but why am I seeing people writing code below:
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
....
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
....
</style>
why is "android:" namespace there? what's the difference between the code above and using value-v21, value-v14, folders?
can someone explain or direct me to the right source?
Yes, if you use AppCompat v21+, you only need a single theme with a parent of Theme.AppCompat (or a subtheme such as Theme.AppCompat.Light) and you do not need the android: namespace attributes for action bar/window related flags, nor separate themes for v14, v20, etc. The full list of top level attributes which AppCompat provides across all API levels can be found in the AppCompat R.styleable Theme.
Much of the code on the internet (including parts of the developer.android.com site) are still written for the pre-v21 AppCompat, which did require both the android: and non-prefixed versions.
Hello i use ActionBarSherlock Version 4.0.0 and i dont know how to change/style the title text, under version 3.5 i used #style/abTextStyle.
but that doenst work in version 4.0.0.
ABS 4 brought with it some major improvements, one being the styling via XML. If you read the documentation on styling, you would know that as of 4.0 -
Due to limitations in Android's theming system any theme
customizations must be declared in two attributes. The normal
android-prefixed attributes apply the theme to the native action bar
and the unprefixed attributes are for the custom implementation. Since
both theming APIs are exactly the same you need only reference your
customizations twice rather than having to implement them twice.
<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
From this we can see that the ABS item reflects the native exactly, obviously without the android prefix.
This in short means that styling the native and ABS actionbar is now much simpler and to do any styling you should follow the standard Android docs on this, and then declare the styling you want like the example above (i.e. declare twice, once for native once for ABS).
This question ActionBar text color has some examples for what you want in its top voted answer, and if you want to be comforted: it was commented on by Jake Wharton who is the genius behind ABS.