How to Change Size of Title's Text on Action Bar

What is the Default ActionBar Title Font Size?

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>

How to change my action bar text color and font size in android

try to add this

actionBar.setTitle(Html.fromHtml("<font color='#ff0000'>ActionBarTitle </font>"));

for font size

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

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

</style>

ActionBar style (Text size)

You can do it programmatically like this

Html.fromHtml("<big><font color=\"white\">" + getString(R.string.app_name_device)+"</big>")

for small text you can change tag <big> with <small>

and if you want to provide specific size of Title Text then you should use Toolbar and use below theme/style

Create one layout toolbar.xml and put below code

<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="?actionBarSize"
android:id="@+id/toolbar"
app:titleTextAppearance="@style/Toolbar.TitleText" />

and change size in

<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">18sp</item>
</style>

and you can inculde above layout in your each Activity layout files like below

<include
layout="@layout/toolbar"
/>

Toolbar in your Activity

ToolBar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setTitle(Html.fromHtml("<big><font color=\"white\">" + getString(R.string.app_name_device)+"</big>"));

How to change the fonts of Title in Action bar in android

Just use these code:

if you are using "Holo Theme" then use this:

    int titleId = getResources().getIdentifier("action_bar_title", "id",
"android");
TextView yourTextView = (TextView) findViewById(titleId);
yourTextView.setTextColor(getResources().getColor(R.color.black));
Typeface yourTypeface = Typeface.createFromAsset(getAssets(), "fonts/your_font.ttf");
//or get from resource
yourTextView.setTypeface(yourTypeface);

if you are using "Material Theme" then use this:

Toolbar toolbar = (Toolbar) findViewById(R.id.action_bar);
TextView textView1 = (TextView) toolbar.getChildAt(0);//title
TextView textView2 = (TextView) toolbar.getChildAt(1);//subtitle
textView1.setTextColor(getResources().getColor(R.color.colorPrimaryDark));
textView2.setTextColor(getResources().getColor(R.color.colorAccent));
Typeface yourTypeface1 = Typeface.createFromAsset(getAssets(), "fonts/your_font1.ttf");
Typeface yourTypeface2 = Typeface.createFromAsset(getAssets(), "fonts/your_font2.ttf");
//or get from resource
textView1.setTypeface(yourTypeface1);
textView2.setTypeface(yourTypeface2);

it works and it is very simple!
Sample Image

How to change the toolbar text size?

Use app:titleTextAppearance:

<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="?actionBarSize"
android:id="@+id/toolbar"
app:titleTextAppearance="@style/Toolbar.TitleText" />

and override the default title size in a custom style:

<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">18sp</item>
</style>

Result:

Screenshot

how to adjust the size of app name in action bar?

you can change the text size of action bar title as below.

<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="?actionBarSize"
android:id="@+id/toolbar"
app:titleTextAppearance="@style/Toolbar.TitleText" />

and override the default title size in a custom style:

<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">18sp</item>
</style>

hope this work!



Related Topics



Leave a reply



Submit