【发布时间】:2018-11-28 13:03:53
【问题描述】:
我正在使用 Jetpack 开发一个用 Kotlin 编写的小型 Android 应用。 我面临一个小问题,我想将我的工具栏标题居中,但我没有设法弄清楚如何。我看到有些人建议使用自定义工具栏布局,但这样做对我来说是不可能的,因为我希望我的第一页命名为“Grateful”,第二页命名为“Details”而没有任何类似的代码
toolbar.setTitle("Details")
我已经尝试在工具栏布局甚至 appbar 上设置 layout_gravity 和重力以及所有这些东西。但没有任何成功。
这是我的 main_Activity 的实际布局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:theme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|snap"
app:titleTextAppearance="@style/TextAppearanceH5"/>
</com.google.android.material.appbar.AppBarLayout>
<fragment
android:id="@+id/main_notes_nav_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/main_nav_notes"/>
</LinearLayout>
我正在使用 Google 提供的导航库及其 Jetpack 开发套件。
谢谢!
【问题讨论】:
-
检查我的评论并将其替换为您的
标签: android kotlin fragment toolbar