【发布时间】:2026-02-22 07:20:03
【问题描述】:
我刚刚使用导航视图的 android studio 模板制作了应用程序。一切正常,但我有以下两个要求
- 我想使工具栏标题居中。
- 我想把图片放在标题旁边。
这是我的 xml:
<?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="com.abdulsalam.lahoreqalander.MainActivity">
<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" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
<!--<android.support.design.widget.FloatingActionButton-->
<!--android:id="@+id/fab"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_gravity="bottom|end"-->
<!--android:layout_margin="@dimen/fab_margin"-->
<!--android:src="@android:drawable/ic_dialog_email" />-->
问题:
我不知道标题字符串保存在哪里,我检查了 string.xml 并且有应用程序名称,并且它完全显示在工具栏标题上。
所以任何建议我可以在哪里更改标题字符串而不更改应用程序名称,事实上我想自定义更改它以及如何将图像放在它旁边。
注意我使用的是Android studio制作的模板
。
【问题讨论】:
-
getSupportActionBar().setTitle("Material Design Samples");
-
getSupportToolBar() 将帮助您获取标题和可绘制对象
-
但是如何设置重力
-
您必须为工具栏集创建自己的样式而不是颜色*.com/a/29533038/3514144
-
而且在 xml 中以设计方式处理它不是更好吗,我想知道在 java 中的代码和 xml 中没有为标题设置字符串,但它是如何使用的该字符串的标题
标签: android android-studio android-toolbar