简体   繁体   English

为什么我不能更改工具栏文本化?

[英]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: 我在styles.xml创建样式,如下所示:

<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. 我设置了titleTextAppearance ,这里的一切看起来都很完美,但它没有用。 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 对于定心重力,请参考这个问题和这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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