Material Design, AppCompat, and Backwards Compatibility - android

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.

Related

Using design library with Theme.Material [duplicate]

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.

Android Themes and styles.xml

(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

how does appcompat library styling work

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.

Any chance to use holoeverywhere and appcompat together?

Since google released the new support library v7, I use the appcompat library instead of actionbarsherlock. With the appcompat library the actionbar still works, if I disable the recreating at orientation change (android:configChanges="orientation|screenSize|keyboardHidden"), which saves me a lot of work. But for the user experiece of android >=2.1 and <3.0 users, i would be happy, if I could continue to use holoeverywhere (which depends on ABS).
I've tried to setup ABS as library for holoeverywhere and then AppCompat and holoeverywhere as libraries for my App, but it doesn't work.
I'd appreciate your help.
EDIT:
I haven't found any solution to get them work together. But I found out, that I can use the Holo Style Generator (link) to change the drawables of most UI components (e.g. EditText etc.). After the theme is generated, you only have to change the parent style in the files from:
res/values/themes_apptheme: <style name="AppTheme" parent="android:Theme.Black">
res/values-v11/themes_apptheme: <style name="AppTheme" parent="android:Theme.Holo">
to
<style name="AppTheme" parent="#style/Theme.AppCompat">
Probably a little late now, but newer versions of HoloEverywhere come with AppCompat instead of ABS.
Personally I tend to struggle with this, as porting ABS projects to AppCompat turned out to be a pain, but there are definitely advantages of using the 'official' solution in the long run.

How do I style the title text in ActionBarSherlock 4.0?

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.

Categories

Resources