0

I am really struggling in theming my android application, i can't understand that how the theme and styles are structured in android, and when to use theme or style for the views.

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.HickersWatch" 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>
</resources>

this is the default theme provided, now what are these things doing like

and rest them, where the code is written for Theme.MaterialComponents.DayNight.DarkActionBar as we are inheriting here. I think i roughly summarise my issue, if this makes sense to anyone of the viewer of this question so please share some **resource** so that i can understand these things (android official doc did not helped me this time), or their **own** solution then please share.
4

1 回答 1

0

这是我用来设置按钮样式的示例

    <style name="button">
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textSize">@dimen/button_text</item>
        <item name="android:textAllCaps">false</item>
        <item name="android:paddingTop">@dimen/padding5</item>
        <item name="android:paddingBottom">@dimen/padding5</item>
        <item name="android:stateListAnimator">@null</item>
    </style>

    <style name="white_button" parent="button">
        <item name="android:background">@drawable/round_shadow_white</item>
        <item name="android:textColor">@color/main_button_background</item>
    </style>

    <style name="blue_button" parent="button">
        <item name="android:background">@drawable/round_shadow_blue</item>
        <item name="android:textColor">@color/white</item>
    </style>

我们设计了两种纽扣,一种​​是白色的,一种是蓝色的,颜色是唯一改变的。所以我们制作了一个名为“button”的主题来圆角,添加填充等。然后我们添加了另一个名为“whit_button”的样式,父样式是button,在这个样式中我们设置了背景颜色和文本颜色。(与 blue_button 相同)。现在我们有了一个白色和蓝色圆角的按钮。当我们想改变所有按钮的半径时,我们必须在一个地方改变它。

我希望这会有所帮助。

于 2021-08-25T17:21:27.470 回答