安卓工具栏标题样式

3

我的意图是使用自定义视图 ( TextView + ImageView ) 并将它作为 Toolbar 的视图。我该怎么样才能得到 Toolbar 默认标题的 TextView 样式呢?我想让我的自定义视图中的 TextView 和默认标题的样式完全一致。我尝试使用以下方式进行样式设置:

setTypeface(Typeface.DEFAULT_BOLD);
setTextSize(18);
setTextColor(Color.BLACK);

但是它看起来仍然不同,这些描述在哪里?因为我真的找不到它们。或者我能以某种方式重用标题的样式吗?当涉及到从代码中进行样式设置时,我有点困惑。
提前致谢。
1个回答

0
在您的坐标布局中,放置这个。
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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" >
        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:text="Ezy Ride"
            android:textColor="#ffffff" />
    </android.support.v7.widget.Toolbar>

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

现在你的应用程序栏布局已经准备好了。按照你的需求进行自定义。

在你的Java代码中

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    TextView toolbarTitle = (TextView)toolbar.findViewById(R.id.title);
    //here set all you want!!

谢谢,但那是我知道的标准方法。在我的当前情况下,必须通过编程完成,并且加粗+ 18 sp看起来非常像标题,但仍然不同。 - Dokuzov
1
有关材料标准,请参阅 https://www.google.com/design/spec/layout/structure.html#structure-app-bar - Sibidharan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接