Android themes & styles demystified - Google I/O 2016

Android Developers · 30K views · 2016 · 36:54

Open on YouTube

Software (other)Web developmenttalk

Why Stack Overflow recommends it

Stack Overflow users link it when explaining the difference between theme attributes and style attributes, such as why colorAccent only works through android:theme.

Recommended by 3 people across 3 different months, 2016 to 2020.

What it is

A Google I/O 2016 session from the Android Developers channel on how Android themes and styles work under the hood. It covers how styles and themes relate, what attributes actually are, and how to use them to keep styles manageable.

What people said

Recommends danypata · 2016-06 · Stack Overflow · on “Android Styles heritage”

So this is an inheritance problem for styles/themse. There are two ways to inherit properties from styles. 1.Through dot notation (implicit): <style name="Theme.AppCompat.NoActionBar.Custom"> // the parent will be Theme.AppCompat.NoActionBar </style> 2.Through parent tag (explicit) <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> //the parent is Theme.AppCompat.Light.DarkActionBar </style> One thing to always remember, explicit inheritance wins over implicit inheritance. So in your case <style name="AppTheme.NoActionBar" parent="@style/AppTheme"> // your parent is AppTheme, and new style is AppThem.NoActionBar, but it doesn't inherit from an actual NoActionBar style. </st

Recommends Tobias Uhmann · 2017-09 · Stack Overflow · on “Meaning of 'android:' prefix within attribute value (e.g. "android:imageButtonStyle")”

In case that anyone else stumbles across the question: I've found the answer in this Droidcon talk: [LINK] The topic is handled in a minute starting at 21:12. As I understand it, specifying no namespace results in the global namespace being searched which seems to include the support libraries attributes. And indeed both, the SDK's R.attr [LINK] as well as the support library's R.attr [LINK] define the imageButtonStyle attribute (with slightly different descriptions). However, the support library does not define a textViewStyle attribute. So that explains why you can't omit it's android: prefix. To answer my last question concerning the documentation: Despite the Google guide and the R.attr

Recommends Eitanos30 · 2020-04 · Stack Overflow · on “Unable to change switch color”

Thanks i watched it all. The instructor says something like :*"coloraccent is a theme attribute so don't try to use it in a layout because nothing will happen"*. **but** he didn't refer to style attribute at all, i think i have problem to understand how a *theme* attributes suce as *textAppearance*, *theme*, *style*, etc are treated when a view is being inflated. I started to watch [this video] , hopefully it will help me to understand. If you have another source to help me i will be glad. Thanks!

Cites Bryan Herbst · 2016-06 · Stack Overflow · on “Selector only works on android 6”

While the android:foreground has existed since API 1, it was only moved up to the View class in API 23 (Marshmallow, 6.0) [this video] . From API 1 until API 23, android:foreground only worked on FrameLayout . Here is a similar question with some solutions for supporting a foreground in earlier versions of Android: How to set foreground attribute to other non FrameLayout view [LINK]

Cites Nouvel Travay · 2016-07 · Stack Overflow · on “meaning of format reference in android attribute”

Let's start with an example <attr name="spinnerDropDownItemStyle" format="reference" /> How do I take this apart and understand it? I watch the Android themes & styles demystified - Google I/O 2016 [this video] talk multiple times and I still don't understand how this reference thing works.

Cites ianhanniballake · 2016-07 · Stack Overflow · on “colorAccent cannot be overridden by child theme”

colorAccent is a theme attribute, not a style attribute as per the Themes and Styles I/O 2016 talk [this video] . Therefore you need to apply it with android:theme , not with style : <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:textIsSelectable="true" android:textColorHighlight="" android:theme="@style/MyCustomTheme"/> And your MyCustomTheme should generally have a parent of ThemeOverlay.AppCompat as it overlays the default theme (changing only the things it defines) rather than resetting everything from the parent theme.

Cites Eugen Pechanec · 2019-05 · Stack Overflow · on “MaterialCardview requires Theme.AppCompat”

According to Material Components 1.2.1 you need to do this: Depend on the library implementation 'com.google.android.material:material:1.2.1' You'll need to have compileSdkVersion 30 Your activity needs to extend AppCompatActivity (or use AppCompatDelegate [LINK] ) You have to use a Material Components theme Source: [LINK] The easiest way to get started is for your current theme to extend Theme.MaterialComponents.*.Bridge instead of Theme.AppCompat.* . Additionally you'll need to override the following attribute in your theme, otherwise the card color will be broken [LINK] : <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge"> <item name="elevationOverlayEnabl