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>
typealias TeardownLogic = () -> Unit fun onCancel(teardown : TeardownLogic){ }
private typealias OnDoggoClick = (dog: Pet.GoodDoggo) -> Unit val onClick: OnDoggoClick
typealias TeardownLogic = () -> Unit //or typealias TeardownLogic = (exception: Exception) -> Unit
fun onCancel(teardown : TeardownLogic){ // can’t easily see what information we have // available in TeardownLogic }
typealias Doggos = List<Pet.GoodDoggo>
fun train(dogs: Doggos){ … }
Chiediti se l'uso di un typealias rende il tuo codice più comprensibile.
typealias AVD = AnimatedVectorDrawable
import android.graphics.drawable.AnimatedVectorDrawable as AVD
import io.plaidapp.R as appR
import io.plaidapp.about.R
expect annotation class Test
actual typealias Test = org.junit.Test
// Kotlin typealias Doggos = List<Pet.GoodDoggo> fun train(dogs: Doggos) { … }
// Decompiled Java code public static final void train(@NotNull List dogs) { … }
I typealias non introducono nuovi tipi.
fun play(dogId: Long)
typealias DogId = Long
fun pet(dogId: DogId) { … }
fun usage() { val cat = Cat(1L) pet(cat.catId) // compiles }