What is the Default ActionBar Title Font Size?

AndroidAndroid Actionbar

Android Problem Overview


Seems to be 17dip. Just want to confirm it if anyone knows the exact size.

Android Solutions


Solution 1 - Android

The short one…

$ grep ActionBar platforms/android-11/data/res/values/* leads to

styles.xml:

<style name="TextAppearance.Widget.ActionBar.Title"
       parent="@android:style/TextAppearance.Medium">
</style>

<style name="TextAppearance.Widget.ActionBar.Subtitle"
       parent="@android:style/TextAppearance.Small">
</style>

[…]

<style name="TextAppearance.Medium">
    <item name="android:textSize">18sp</item>
</style>

<style name="TextAppearance.Small">
    <item name="android:textSize">14sp</item>
    <item name="android:textColor">?textColorSecondary</item>
</style>

Solution 2 - Android

This works for me.

This is what I do to get the default toolbar style:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar_top"
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:background="@color/primary_dark">

    <TextView
        android:id="@+id/toolbar_title"
        style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

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

This does the trick to keep the default style style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"

Then in your activity, you can do:

Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);
mTitle.setText("Custom...");

Solution 3 - Android

I use this code to get the text size of title and subtitle of Toolbar

val toolbar = findViewById<Toolbar>(R.id.myToolbar)
val titleSize =
    (toolbar.getChildAt(0) as AppCompatTextView).textSize / resources.displayMetrics.density
val subTitleSize =
    (toolbar.getChildAt(1) as AppCompatTextView).textSize / resources.displayMetrics.density
// hard code position 0 for title and 1 for subTitle may not work in all case, depend in your case, you can use a suitable value

Log.i("TAG", "title size $titleSize")
Log.i("TAG", "sub title size $subTitleSize")

with my current theme Theme.MaterialComponents.DayNight.DarkActionBar with androidx.appcompat.widget.Toolbar. title size is 20 and subtitle is 16

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaimangoView Question on Stackoverflow
Solution 1 - AndroidRenaudView Answer on Stackoverflow
Solution 2 - AndroidJiyehView Answer on Stackoverflow
Solution 3 - AndroidLinhView Answer on Stackoverflow