tsengvn / typekit

148 stars 27 forks source link

It doesn't change toolbar title and actions fonts #4

Closed alirezaafkar closed 8 years ago

ParkSangGwon commented 8 years ago

I had same problem before. now my toolbar title can adjust typekit ( as custom font) you can add TextView inside your toolbar View.

this is my toolbar.xml code.

<?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:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/custom_main"
    android:minHeight="?attr/actionBarSize"
    android:elevation="@dimen/toolbar_elevation"
    android:paddingTop="@dimen/tool_bar_top_padding"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

    >

        <TextView
            android:id="@+id/tv_toolbar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:textColor="@color/white"
            style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"

            />

</android.support.v7.widget.Toolbar>

and you need some code in your activity.

you have to override setTitle() method. when setTitle() is called, you have to setText to your TextView


    @Override
    public void setTitle(CharSequence title) {

        if (getSupportActionBar() == null)
            return;

        if (tv_toolbar_title != null) {

            getSupportActionBar().setDisplayShowTitleEnabled(false);
            tv_toolbar_title.setText(title);
        } else {

            getSupportActionBar().setDisplayShowTitleEnabled(true);
            super.setTitle(title);
        }

    }
oatpano commented 8 years ago

I can change toolbar title font.

//in activity

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);

//xml

<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">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@android:color/white"
                android:textSize="24sp"/>

</android.support.v7.widget.Toolbar>
vickychijwani commented 8 years ago

Can this be closed, since the original issue appears to be resolved?