0

Here's my styles.xml file.

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary4</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark4</item>
        <item name="colorAccent">@color/colorAccent2</item>
        <item name="android:fontFamily">fonts/HelveticaNeue-Light.ttf</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="AppTheme.Widget" />

    <style name="AppTheme.Widget.TextView" parent="android:Widget.Holo.Light.TextView">
        <item name="android:fontFamily">fonts/HelveticaNeue-Light.ttf</item>
    </style>
</resources>

And this is the layout file that contains the toolbar.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true"
    tools:context=".HomeActivity">

    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

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

</android.support.design.widget.CoordinatorLayout>

So, The toolbar is using the AppTheme.PopOverlay theme which is defined in the styles.xml file.

Currently the title on the toolbar is set as the default app name, and I wanted to change the title, so I already tried to include the <item name="android:text">@string/customtitle</item> attribute in the AppTheme.PopOverlay theme. It didn't work.

Now started to wonder, how is the title defined by default as the app name, and how I can change it.

Added What I want to find out fundamentally from this question is, how the title is set by default with the app name in the toolbar even though it is not defined in any parts of the XML files, AndroidManifest.xml or in the codes.

MarshallLee
  • 1,290
  • 4
  • 23
  • 42
  • 1
    Do you need this to be strictly done in XML or would you be fine with a solution that did it programmatically? – asadmshah Dec 03 '15 at 16:17
  • I prefer to do it with XML but I would also like to find out the way to make it programmatically. – MarshallLee Dec 03 '15 at 16:17
  • and as stated before http://stackoverflow.com/questions/8607707/how-to-set-a-custom-font-in-the-actionbar-title?lq=1 you should search before you ask – Viktor Yakunin Dec 03 '15 at 16:27

3 Answers3

6

You can change the title in two ways:

Programmatically (in your Activity):

setTitle("Title");

XML (in your Manifest):

<activity android:name=".SomeClass" android:label="Title" />  

To change the font of the actionbar you can consider this post: How to Set a Custom Font in the ActionBar Title?

Community
  • 1
  • 1
Dennis Kriechel
  • 3,719
  • 14
  • 40
  • 62
1

You can change title by this code

setTitle("Your Tittle");
Raza Ali Poonja
  • 1,086
  • 8
  • 16
0

You can do it by:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Hi!");
Héctor
  • 24,444
  • 35
  • 132
  • 243