42

There is an ActionBar on each Android 4.0 application, and it got a title. I need to make this size less. But I don't understand how I can do it, because ActionBar doesn't provide public methods for it. Remark: I don't want to use custom views.

God
  • 1,238
  • 2
  • 18
  • 45
malcoauri
  • 11,904
  • 28
  • 82
  • 137

6 Answers6

51

Actually, you can do what you want to customize the ActionBar. It must be done through the Theme. You can do something like this :

<style name="Theme.YourTheme" parent="android:style/Theme">
    <item name="android:actionBarStyle">@style/Theme.YourTheme.Styled.ActionBar</item>
</style>

<style name="Theme.YourTheme.Styled.ActionBar">
    <item name="android:titleTextStyle">@style/Theme.Viadeo.Styled.YourTheme.TitleTextStyle</item>
</style>

<style name="Theme.YourTheme.Styled.ActionBar.TitleTextStyle" parent="@android:style/Widget.TextView">
    <item name="android:textSize">12sp</item>
</style>
Aurélien Guillard
  • 1,203
  • 8
  • 20
  • 2
    Thanks Aurélien! You should consider using sp inshead of dp for text size ;-) – gingo Nov 27 '13 at 16:28
  • 8
    Instead of hardcoding any size, you can consider inheriting from `parent="@android:style/TextAppearance.Large"` instead. That will give you the standard larger text size, no matter what device you're on. – Gábor Mar 23 '14 at 12:30
  • nice work i use this styling way for action bar and change the color and size and appearance of the title – Milaaaad Dec 17 '15 at 11:31
23

You could always do something like this:

ActionBar actionBar = getActionBar();
actionBar.setTitle(Html.fromHtml("<small>YOUR TITLE</small>"));
Matt W
  • 686
  • 1
  • 9
  • 12
7

on my system, res/styles AppTheme has a note saying

<!-- All customizations that are NOT specific to a particular API-level can go here. -->

and this is the style indicated in AndroidMainfest.xml. I added

<item name="android:textSize">15sp</item>

and it worked and I'd rather do this than a custom actionbar.

steven smith
  • 1,519
  • 15
  • 31
6

I have followed this method to skip the creation of custom style:

  1. Create a custom layout with required text size and
  2. apply that to your action bar.

1) Create a layout file (titlebar.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/action_bar_title"
        android:text="@string/app_name"
        android:textColor="@color/colorPrimary"
        android:textSize="24sp" />
</LinearLayout>

Here set your required textSize.

2) MainActivity.java

    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); //bellow setSupportActionBar(toolbar);
    getSupportActionBar().setCustomView(R.layout.titlebar);

hope this helps.

Steephan Selvaraj
  • 1,629
  • 3
  • 15
  • 18
3

The text's size in Android ActionBar is standard.

Since ICS, Android now develops a standard so that applications will (hopefully) follow the same UI guidelines and design principles.

http://developer.android.com/guide/practices/ui_guidelines/index.html

This is why you can't change it.

However, if you still want to do so, you could use a custom Theme or maybe implement ActionBar (a fork) and modify its sources: https://github.com/johannilsson/android-actionbar to get maximum control.

shkschneider
  • 17,833
  • 13
  • 59
  • 112
  • 4
    You could. But you shouldn't. Android's chrome is designed by UI professionals who study how a user interacts with a device, and optimize appearance and placement of all UI elements to facilitate good interaction. Modifying the chrome will make an app less usable and frustrate users. – 323go Oct 15 '12 at 14:31
0

You can use

subtitle:"exsample"

XML

 <androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:theme="?attr/actionBarTheme"
    app:subtitle="subTitle"
    app:title = "Title"
    android:tag="dff"/>

JAVA

getSupportActionBar.setSubtitle("Sub Title");
Community
  • 1
  • 1