Answer the question
In order to leave comments, you need to log in
Why is ThemeOverlay needed?
I understand styles and themes. I just can't understand why themes with the ThemeOverlay prefix are needed?
There is such a definition on the web:
ThemeOverlay are special “lightweight” themes that allow you to override the attributes of the main theme for the View component.
But why should I use it if I can make my own theme with overriding the attribute I need? For example like this:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Styles" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
<!--Обычное переопределение темы-->
<style name="Theme.Styles.CustomTheme">
<item name="android:textColor">@color/red</item>
</style>
</resources>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/Theme.Styles.CustomTheme"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question