gpt4 book ai didi

android - 如何使工具栏中的标题居中(即使显示了工具栏后退按钮)

转载 作者:可可西里 更新时间:2023-11-01 19:06:54 26 4
gpt4 key购买 nike

如何将工具栏中的 Activity 标题居中,以便它也可以与显示的工具栏后退按钮一起使用?

目前,我发现的最佳解决方案是在显示后退按钮时留出 60dp 的边距。

最佳答案

仅使用后退按钮时,这对我有用。在 XML 中:

<android.support.v7.widget.Toolbar
android:id="@+id/tb_title_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white">

<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textAllCaps="true"
android:textColor="#2B2B2B"
android:textSize="14sp" />

</android.support.v7.widget.Toolbar>

在java代码中:

int contentInsetStartWithNavigation = mTitleContainer.getContentInsetStartWithNavigation();
mTitleContainer.setContentInsetsRelative(0, contentInsetStartWithNavigation);

关于android - 如何使工具栏中的标题居中(即使显示了工具栏后退按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32160012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com