Java 如何在Android中创建自定义工具栏?
我在对齐工具栏中的项目时遇到问题,每个创建的项目都设置为右侧,因此我想知道是否可以创建自定义工具栏,具体如下所示:Java 如何在Android中创建自定义工具栏?,java,android,xml,Java,Android,Xml,我在对齐工具栏中的项目时遇到问题,每个创建的项目都设置为右侧,因此我想知道是否可以创建自定义工具栏,具体如下所示: 中间的一个文本,两个项目,一个在左边,一个在右边。我编辑这张图片是为了了解我需要什么。 希望很清楚您可以使用以下代码在Android中创建自定义工具栏: <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" style="@s
中间的一个文本,两个项目,一个在左边,一个在右边。我编辑这张图片是为了了解我需要什么。
希望很清楚您可以使用以下代码在Android中创建自定义工具栏:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center"
android:text="@string/app_name"
android:textAppearance="?attr/textAppearanceHeadline5" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:src=""
android:contentDescription="@null"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:src=""
android:contentDescription="@null"
/>
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
注意:我已经使用了Androidx,请确保您也在使用相同的工具条,或者只需将工具栏更改为v7 support one。向我们展示一些代码。是的,这是可能的。你在做这件事时遇到了什么具体问题?你尝试了什么,当你尝试的时候发生了什么?