Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 849
Monster Hunter Avatar asked Feb 22 '26 17:02

Monster Hunter


1 Answers

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.

like image 103
ianhanniballake Avatar answered Feb 25 '26 07:02

ianhanniballake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!