【发布时间】:2020-01-21 17:48:52
【问题描述】:
【问题讨论】:
标签: android android-layout android-toolbar
【问题讨论】:
标签: android android-layout android-toolbar
假设您使用的是android.widget.Toolbar,您正在寻找字幕。这可以在 XML 中设置:
<Toolbar
android:subtitle="@string/your_string_here"
.../>
或者在代码中:
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setSubtitle(R.string.your_string_here);
如果您使用提供默认工具栏的 AppCompat 主题,您可以通过getSupportActionBar() 访问它。这将返回 android.support.v7.app.ActionBar(或 androidx 等效项),但语法相同:
ActionBar actionbar = getSupportActionBar();
actionbar.setSubtitle(R.string.your_string_here);
【讨论】:
您必须创建自定义工具栏,轻松创建自己的设计完美:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@color/action_bar_bkgnd"
app:theme="@style/ToolBarTheme" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
这意味着您可以随意设置 TextView 的样式,因为它只是一个常规的 TextView。因此,在您的活动中,您可以像这样访问标题:
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);
【讨论】: