当启用后退按钮或hamberger Button时,位于工具栏标题末尾的自定义工具栏侧面textView分离了

问题描述 投票:1回答:3

enter image description here

<androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center">

                <TextView
                    android:id="@+id/toolbar_text_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="?android:attr/actionBarSize"
                    android:fontFamily="@font/inter_semi_bold"
                    android:textColor="@color/layout_main_text_color"
                    android:textSize="@dimen/_20ssp"
                    tools:text="Toolbar" />

                <TextView
                    android:id="@+id/total_job_text_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_toEndOf="@+id/toolbar_text_view"
                    android:background="@drawable/rectangle_blue_gradient_with_thirty_radius"
                    android:paddingLeft="@dimen/_7sdp"
                    android:paddingTop="@dimen/_1sdp"
                    android:paddingRight="@dimen/_7sdp"
                    android:paddingBottom="@dimen/_1sdp"
                    android:text="1425"
                    android:textColor="@color/white"
                    android:textSize="@dimen/_7ssp" />

            </RelativeLayout>

        </androidx.appcompat.widget.Toolbar>

在此项目中,我使用导航组件。我想在“工作板”旁边的蓝色边框中显示数字。我看了看这个解决方案。Toolbar title not in center when Back Button is enable该解决方案能够解决将工具栏文本居中居中而不是居中居中的问题。我想要这种类型的输出enter image description here

android android-layout android-toolbar
3个回答
1
投票

添加此行


1
投票

尝试删除android:layout_marginEnd =“?android:attr / actionBarSize”


1
投票

将工具栏的文本边距修改为较小的值。

© www.soinside.com 2019 - 2024. All rights reserved.