Gli stili sono una raccolta di attributi di visualizzazione; specifici per un singolo tipo di widget
<!-- Copyright 2019 Google LLC. SPDX-License-Identifier: Apache-2.0 --> <style name="Widget.Plaid.Button.InlineAction" parent="…"> <item name="android:gravity">center_horizontal</item> <item name="android:textAppearance">@style/TextAppearance.CommentAuthor</item> <item name="android:drawablePadding">@dimen/spacing_micro</item> </style>
<!-- Copyright 2019 Google LLC. SPDX-License-Identifier: Apache-2.0 --> <Button … android:gravity="center_horizontal" android:textAppearance="@style/TextAppearance.CommentAuthor" android:drawablePadding="@dimen/spacing_micro"/>
<!-- Copyright 2019 Google LLC. SPDX-License-Identifier: Apache-2.0 --> <Button … style="@style/Widget.Plaid.Button.InlineAction"/>
<!-- Copyright 2019 Google LLC. SPDX-License-Identifier: Apache-2.0 --> <style name="Theme.Plaid" parent="…"> <item name="colorPrimary">@color/teal_500</item> <item name="colorSecondary">@color/pink_200</item> <item name="android:windowBackground">@color/white</item> </style>
I temi sono una raccolta di risorse denominate, utili in generale in un'app
/* Copyright 2019 Google LLC. SPDX-License-Identifier: Apache-2.0 */ interface ColorPalette { @ColorInt val colorPrimary @ColorInt val colorSecondary } class MyView(colors: ColorPalette) { fab.backgroundTint = colors.colorPrimary }
/* Copyright 2019 Google LLC. SPDX-License-Identifier: Apache-2.0 */ val lightPalette = object : ColorPalette { … } val darkPalette = object : ColorPalette { … } val view = MyView(if (isDarkTheme) darkPalette else lightPalette)
<!-- Copyright 2019 Google LLC. SPDX-License-Identifier: Apache-2.0 --> <!-- AndroidManifest.xml --> <application … android:theme="@style/Theme.Plaid"> <activity … android:theme="@style/Theme.Plaid.About"/> <!-- layout/foo.xml --> <ConstraintLayout … android:theme="@style/Theme.Plaid.Foo">
<!-- Copyright 2019 Google LLC. SPDX-License-Identifier: Apache-2.0 --> <ViewGroup … android:background="?attr/colorSurface">
Usa la sintassi ?attr/themeAttributeName per eseguire una query al tema per il valore di questo attributo semantico
<!-- Copyright 2019 Google LLC. SPDX-License-Identifier: Apache-2.0 --> <ViewGroup … android:theme="@style/Theme.App.SomeTheme"> <! - SomeTheme also applies to all child views. --> </ViewGroup>