Reputation: 1567
Seems to be 17dip. Just want to confirm it if anyone knows the exact size.
Upvotes: 83
Views: 83440
Reputation: 60923
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
Upvotes: 0
Reputation: 5297
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...");
Upvotes: 88
Reputation: 8873
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>
Upvotes: 124