7

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

  • i searched a lot but couldnt figure out how to centre title using style. But you can do it programatically as shown in the first answer here http://stackoverflow.com/questions/29443604/android-how-to-centered-title-int-toolbar-in-android or create a custom toolbar layout as shown here http://stackoverflow.com/questions/26533510/android-toolbar-center-title-and-custom-font – Shreyans Mar 21 '16 at 01:39
  • also edit the question title to include the gravity problem. or maybe edit it out of the question body and ask a new question about the gravity error if above methods dont solve it – Shreyans Mar 21 '16 at 01:42
  • if you can get reference to the textview like by findview by id function, you can set layoutparam by code – SHICONG CAO Mar 21 '16 at 03:24

1 Answers1

12

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

Community
  • 1
  • 1
Shreyans
  • 1,043
  • 2
  • 14
  • 25
  • 1
    Thanks, it worked. But I couldn't set gravity center. How can I see text in center and is it possible set text multiline ? – whatwasmynickname Mar 21 '16 at 00:44
  • well just a wild guess but did you try 'app' instead of 'android' there too? if that doesnt fix it ill do some googling :) – Shreyans Mar 21 '16 at 00:46
  • shit that doesnt work sorry. i need a pic of how your toolbar looks at present. can you edit the question and add a pic? – Shreyans Mar 21 '16 at 00:52