简体   繁体   中英

Why can't I change toolbar textsize?

I want to change my toolbar text size and gravity. I create style in styles.xml like this:

<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textSize">16sp</item>
    <item name="android:textStyle">normal</item>
    <item name="android:color">@color/colorHighlight</item>
    <item name="android:gravity">center</item>
</style>

and I set titleTextAppearance , everything here looks perfect but it didn't worked. My custom toolbar:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="#009688"
    android:titleTextAppearance="@style/Toolbar.TitleText"
    android:paddingTop="0dp"
    app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

</android.support.v7.widget.Toolbar>

What is wrong with my toolbar?

my toolbar

try using

app:titleTextAppearance="@style/Toolbar.TitleText"

instead of

android:titleTextAppearance="@style/Toolbar.TitleText"

as shown here

For centering gravity refer to this question and this question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM