如何在android工作室的工具栏中心图标

如何在android工作室的工具栏中心图标,第1张

概述我问了一个类似的问题 here … 我在答案中有一些教程. 但这个问题是差异的.因为没有一个方法在我的项目中不起作用. 我想要工具栏中的所有图标 我测试所有可用的方式…但总是图标漂浮在左边. 我想要中心图标(我更喜欢左图标浮动左右图标浮动右边和其他图标浮点中心) Activity.Main.xml <LinearLayout xmlns:android="http://schemas.androi 我问了一个类似的问题 here …
我在答案中有一些教程.
但这个问题是差异的.因为没有一个方法在我的项目中不起作用.

我想要工具栏中的所有图标

我测试所有可用的方式…但总是图标漂浮在左边.

我想要中心图标(我更喜欢左图标浮动左右图标浮动右边和其他图标浮点中心)

Activity.Main.xml

<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical"   // I add vertical    tools:context=".MainActivity">    <include        androID:ID="@+ID/tool_bar"        layout="@layout/tool_bar"        androID:layout_height="wrap_content"        androID:layout_wIDth="match_parent"  // I add match_parent        androID:layout_gravity="center" />   // I add center</linearLayout>.

也在tool_bar.xml中

<?xml version="1.0" enCoding="utf-8"?><androID.support.v7.Widget.Toolbar    androID:layout_height="wrap_content"    androID:layout_height="match_parent"    androID:background="@color/colorPrimary"    androID:elevation="2dp"    androID:theme="@style/Base.themeOverlay.AppCompat.Dark"    androID:layout_gravity="center"  // I add center    xmlns:androID="http://schemas.androID.com/apk/res/androID" />

在main_menu.xml中

<menu 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" tools:context=".MainActivity"><item    androID:ID="@+ID/action_forward"    androID:title="forward"    androID:icon="@drawable/ic_action_arrow_forward"    app:showAsAction="always"    ></item><item    androID:ID="@+ID/action_zoom_in"    androID:title="zoom in"    androID:icon="@drawable/ic_action_zoom_in"    app:showAsAction="always"    ></item><item ...

对于< item>中的上述代码(main_menu.xml)我尝试了所有这些代码:

androID:layout_wIDth="match_parent"androID:layout_weight=".2" // 20%androID:gravity="center"androID:layout_centerVertical="true"androID:layout_centerHorizontal="true"

我真的不知道我可以做什么来对齐图标.
我上了几个小时,我尝试了所有的会议

我怎么了?
对于所有的测试我看不到任何改变…

之前我想要pic2(在上图)但现在我只想要中心!

对于我所有的测试,我只得到图1,没有任何改变.

解决方法 解决问题,享受:)
<androID.support.v7.Widget.Toolbar    androID:ID="@+ID/toolbar"    androID:layout_wIDth="match_parent"    androID:layout_height="?attr/actionbarSize"    androID:elevation="4dp"    androID:background="?attr/colorPrimary">    <!-- Code for your left button -->    <ImageVIEw        androID:ID="@+ID/yourID"        androID:src="@mipmap/yourleftIcon"        androID:layout_wIDth="wrap_content"        androID:layout_height="fill_parent"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        androID:layout_margintop="4dp"        androID:layout_marginBottom="4dp"        androID:layout_gravity="left" />        <!-- Here is the main code for your MIDdle buttons -->        <linearLayout            androID:layout_wIDth="wrap_content"            androID:layout_height="match_parent"            androID:orIEntation="horizontal"            androID:layout_gravity="center"            androID:gravity="center">            <button                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:background="@drawable/ic_launcher"                androID:ID="@+ID/button1"/>            <button                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:background="@drawable/ic_launcher"                androID:ID="@+ID/button2"/>            <button                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:background="@drawable/ic_launcher"                androID:ID="@+ID/button3"/>            <button                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:background="@drawable/ic_launcher"                androID:ID="@+ID/button4" />        </linearLayout>    <!-- Code for your Right button -->    <ImageVIEw        androID:ID="@+ID/yourID"        androID:src="@mipmap/yourRightIcon"        androID:layout_wIDth="wrap_content"        androID:layout_height="fill_parent"        androID:layout_marginleft="20dp"        androID:layout_marginRight="20dp"        androID:layout_margintop="4dp"        androID:layout_marginBottom="4dp"        androID:layout_gravity="right" /></androID.support.v7.Widget.Toolbar>
总结

以上是内存溢出为你收集整理的如何在android工作室的工具栏中心图标全部内容,希望文章能够帮你解决如何在android工作室的工具栏中心图标所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1132673.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存