-
Notifications
You must be signed in to change notification settings - Fork 24
Android Theme and style Toolbar
Roman edited this page Mar 21, 2019
·
3 revisions
Стандартный виджет Toolbar:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:navigationIcon="@drawable/ic_arrow_back"
/>Основные атрибуты (используемые в androidx.appcompat.widget.Toolbar):
android:backgroundtitleTextAppearancetitleTextColorsubtitleTextAppearancesubtitleTextColor
Cтиль по умолчанию берётся из атрибута темы toolbarStyle. Для темы Theme.MaterialComponents.NoActionBar выставлен стиль по умолчанию:
<item name="toolbarStyle">@style/Widget.MaterialComponents.Toolbar</item>Стандартные стили:
Widget.MaterialComponents.Toolbar
<style name="Widget.MaterialComponents.Toolbar" parent="Widget.AppCompat.Toolbar">
<item name="titleTextAppearance">?attr/textAppearanceHeadline6</item>
<item name="titleTextColor">?android:attr/textColorPrimary</item>
<item name="subtitleTextAppearance">?attr/textAppearanceSubtitle1</item>
<item name="subtitleTextColor">?android:attr/textColorSecondary</item>
</style>!!! Обратить внимание, используется textAppearanceHeadline6 и textAppearanceSubtitle1
Widget.MaterialComponents.Toolbar.Primary
<style name="Widget.MaterialComponents.Toolbar.Primary">
<item name="android:background">?attr/colorPrimary</item>
<item name="titleTextColor">?attr/colorOnPrimary</item>
<item name="subtitleTextColor">?attr/colorOnPrimaryEmphasisMedium</item>
</style>Widget.MaterialComponents.Toolbar.Surface
<style name="Widget.MaterialComponents.Toolbar.Surface">
<item name="android:background">?attr/colorSurface</item>
<item name="titleTextColor">?attr/colorOnSurfaceEmphasisHighType</item>
<item name="subtitleTextColor">?attr/colorOnSurfaceEmphasisMedium</item>
</style>Отличаются тем, из каких атрибутов берутся цвета для заголовков и фона.