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

3
  • 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 stackoverflow.com/questions/29443604/… or create a custom toolbar layout as shown here stackoverflow.com/questions/26533510/…
    – Shreyans
    Mar 21, 2016 at 1: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, 2016 at 1:42
  • if you can get reference to the textview like by findview by id function, you can set layoutparam by code Mar 21, 2016 at 3:24

1 Answer 1

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

3
  • 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 ? Mar 21, 2016 at 0: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, 2016 at 0: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, 2016 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.