Toolbar Title

How / Is it possible to occupy the title of the entire width of the toolbar? Currently, text is disabled by menu items.

Ive tried to do with the various attributes of the xml, such as paddingEnd, contentInsetRight, titleMarginEndwithout result.

Thank!:)

Toolbar with ellipsized title

+4
source share
2 answers

Typically, the title should always be located between the toolbar menu and the action items to move the title when the toolbar collapses.

TextView . , LinearLayout ( , KitKat).

<!-- App Bar container -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/blue"
    android:elevation="2dp"
    android:orientation="vertical">

    <!-- App Bar -->
    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:elevation="0dp"
        android:gravity="center"
        android:minHeight="?attr/actionBarSize">
    </android.support.v7.widget.Toolbar>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="6dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:text="Title below the AppBar itself."
        android:textColor="#fff"
        android:textSize="20sp"/>
</LinearLayout>

:

Full name of the width between the windows

, , ToolBar, TextView . .

+1

private void fixToolbarTitleBug()
{
    fixToolbarTitleBug("mTitleTextView");
}

private void fixToolbarTitleBug(String fieldName)
{
    try
    {
        Field field=Toolbar.class.getDeclaredField(fieldName);
        field.setAccessible(true);
        TextView titleTextView=(TextView) field.get(toolbar);
        Toolbar.LayoutParams params=(Toolbar.LayoutParams) titleTextView.getLayoutParams();
        params.width=ScreenSize.width()*3/4; //replace this
        titleTextView.setLayoutParams(params);
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}

: setTitle, , mTitleTextView , .

supportActionBar.setTitle(title);
fixToolbarTitleBug();

,

private void fixToolbarSubtitleBug()
{
    fixToolbarTitleBug("mSubtitleTextView");
}

:

supportActionBar.setSubtitle(subtitle);
fixToolbarSubtitleBug();
0

All Articles