Showing posts with label toolbar textsize. Show all posts
Showing posts with label toolbar textsize. Show all posts

Thursday, May 21, 2015

Set text size for Toolbar

Since Toolbar doesnt provide a textSize attribute to set the text size of the Title you have to add a TextView and pass the title text to it.
Ofcourse you can instead use setTitleTextAppearance where you can set color, size, style etc.

For the first solution the steps you got to follow are :


1) remove default title :
    getSupportActionBar().setDisplayShowTitleEnabled(false);

2) Add TextView in Toolbar :

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/toolbar"
        android:minHeight="?android:attr/actionBarSize"
        android:layout_width="match_parent"
        android:layout_height="@dimen/toolbar_height"
        android:background="@color/colorPrimary"
        android:theme="@style/ActionBarThemeOverlay"
       android:popupTheme="@style/ActionBarPopupThemeOverlay">

    <TextView
        android:id="@+id/tv_toolbar"
        android:textSize="@dimen/toolbar_textSize"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

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

3) Set toolbar_textSize on dimens.xml :

<dimen name="toolbar_textSize">16sp</dimen>


Now toolbar's title size is the one you specify on the dimens.xml  file. That's it 16sp in our code.
We prefer sp units (instead of dp) so the size can scale when user changes the font size on her/his device.