android - 如何在工具栏菜单中居中(水平)图标
问题描述
如何在工具栏菜单中将图标居中,我尝试添加填充或边距但不起作用。如何在工具栏菜单中将图标居中,我尝试添加填充或边距但不起作用。
这是代码,如果我需要上传更多源代码,请告诉我。 主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/item1"
android:icon="@drawable/ic_credit_card_black_24dp"
android:title=" "
app:showAsAction="ifRoom"/>
<item
android:id="@+id/item2"
android:icon="@drawable/ic_credit_card_black_24dp"
android:title=" "
app:showAsAction="ifRoom"/>
</menu>
menu_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/colappsingtoolbar"
android:layout_width="match_parent"
android:layout_height="250dp"
app:layout_scrollFlags="exitUntilCollapsed|scroll"
app:contentScrim="?attr/colorPrimary"
app:title=" "
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp" >
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mainimg"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />
解决方案
我不知道是否存在一种简单的方法,但您可以创建 CustomToolbar。例如,创建一个名称为:toolbar 的 xml 布局
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/tool_bar_size_mio"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="10">
<Button
android:id="@+id/btn_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button"/>
</LinearLayout>
然后,包括到您的活动 xml
<include
android:id="@+id/toolbar"
layout="@layout/toolbar_menu_principal" />
推荐阅读
- php - 错误:SQLSTATE[HY000] [2002] 没有这样的文件或目录
- ios - 适用于 XML 等标准文件类型的 iOS 应用自定义图标
- python - Python + Selenium:在 WebDriverWait 调用超时后重新加载页面
- r - 删除R中列中带有数字的行
- android - 应用程序关闭或最小化时需要打开 Notification.java 活动
- node.js - 从 ESP8266WiFi 获取 json 字符串,并将其保存为 NodeJS 中的字符串变量以写入 CSV 文件
- z3 - Z3 Prover 在命令行中增加时间和内存
- php - PHP 消息和 PHP 警告 ZipArchive::close(): Write error: No space left on device
- c# - 如何根据 Int 列表获取精确匹配列表对象?
- web-scraping - 如何在 instagram 中删除所有主题标签的帖子