3

I've been spending hours trying to fix the changing action bar title size according to this stack overflow post: Android Toolbar: small title text in landscape mode

Unfortunately, it seems that no matter what I do, anything regarding the actionbar style won't actually apply.

My styles v14 file:

<!-- Main theme -->
<style name="MyTheme" parent="Theme.AppCompat">
    <item name="android:actionBarItemBackground">@drawable/selectable_background</item>
    <item name="android:popupMenuStyle">@style/PopupMenu</item>
    <item name="android:dropDownListViewStyle">@style/DropDownListView.MyTheme</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.MyTheme</item>
    <item name="android:actionDropDownStyle">@style/DropDownNav.MyTheme</item>
    <item name="android:spinnerItemStyle">@style/Widget.MyTheme.TextView.SpinnerItem</item>
    <item name="android:spinnerDropDownItemStyle">@style/Widget.MyTheme.DropDownItem</item>
</style>

My ActionBar styles:

<style name="Widget.MyTheme.ActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="android:background">@drawable/ab_solid</item>
    <item name="android:titleTextStyle">@style/my_title_style</item>
</style>

<style name="my_title_style" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="textSize">20sp</item>
</style>

And, of course, "MyTheme" is applied in the manifest as well - I've even tried adding it to all the individual activities as well, to no avail.

It seems that no matter what I do, stuff just won't apply. I've tried removing the android: namespace, I've tried using titleTextAppearance instead of titleTextStyle, I've basically emulated exactly how the parent themes do it, but it won't change anything. Anybody have a clue as to what's going on? I just recently updated to AppCompat so I'm not totally familiar with how everything works.

Community
  • 1
  • 1
Mikey Chen
  • 2,370
  • 1
  • 19
  • 31

3 Answers3

2

You need to use

<item name="background">@drawable/ab_solid</item>
<item name="titleTextStyle">@style/my_title_style</item>

for support library compatibility into your style.

Read Styling the Action Bar, section "For Android 2.1 and higher". Where it is given that you need to use two entries like

<style name="CustomActionBarTheme"
           parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

So your complete style would be

<style name="Widget.MyTheme.ActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="android:background">@drawable/ab_solid</item>
    <item name="android:titleTextStyle">@style/my_title_style</item>
    <item name="background">@drawable/ab_solid</item>
    <item name="titleTextStyle">@style/my_title_style</item>
</style>
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
0

I don“t know if it's all that ou have made, but you have to add this code in the manifest(in the activity you want to apply this style):

<activity
    android:name=".MyActivity"
    android:label="@string/appName"
    android:theme="@style/my_little_style" >
</activity>
Rene Limon
  • 614
  • 4
  • 16
  • 34
0

Try in this way:

  • Create a layout for your Toolbar and put a TextView:

    <?xml version="1.0" encoding="utf-8"?>
    <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_height="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:id="@+id/toolbar"
        android:background="#b2b2b2">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:id="@+id/toolbar_title"
            android:textSize="20sp"
            android:textColor="#ff282828"/>
    
       </android.support.v7.widget.Toolbar>
    
  • Include the layout in your .xml:

    <include layout="@layout/toolbar_activities"
        android:id="@+id/toolbar_layout"/>
    
  • Finally set a title in your java class:

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_layout);
    
    TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
    mTitle.setText("Your Title");
    setSupportActionBar(toolbar)
    
Rick
  • 3,943
  • 6
  • 33
  • 45