我想实现自定义ActionBar,必须如下所示:

所以问题:
ActionBar?ActionBar或什么?我在这里问了一个类似的问题......我在答案中得到了一些教程.但这个问题是diffrenet.因为这个方法都没有在我的项目中起作用.
我想要中心工具栏中的所有图标
我测试了所有可用的方式......但总是图标在左边浮动.
我想要居中的图标(我更喜欢左侧图标浮动左右图标浮动右侧,其他图标浮动中心)
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>.
Run Code Online (Sandbox Code Playgroud)
也在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" />
Run Code Online (Sandbox Code Playgroud)
在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 ...
Run Code Online (Sandbox Code Playgroud)
对于上面的代码(main_menu.xml),<item>我尝试了所有这些代码:
android:layout_width="match_parent"
android:layout_weight=".2" …Run Code Online (Sandbox Code Playgroud) android android-layout android-menu android-studio android-toolbar
我有一个带分割操作栏的应用程序加载一个动作菜单.
我更改了新工具栏的操作栏,并用独立模式中使用的其他工具栏替换了拆分操作栏:
Toolbar toolbarBottom = (Toolbar) findViewById(R.id.toolbarBottom);
toolbarBottom.inflateMenu(R.menu.ab_one_cam);
Run Code Online (Sandbox Code Playgroud)
如文档中所指定,操作菜单位于工具栏右侧的引脚:

但我希望图标在工具栏上居中,就像它在拆分操作栏上一样:

如何使操作菜单占用工具栏上的所有可用空间?
工具栏专用于此菜单,不会在其上添加任何其他内容.
回答
接受的答案链接指向拆分工具栏.如果像我这样你需要这个代码就足够了:
public class SplitToolbar extends Toolbar {
public SplitToolbar(Context context) {
super(context);
}
public SplitToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SplitToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void addView(View child, ViewGroup.LayoutParams params) {
if (child instanceof ActionMenuView) {
params.width = LayoutParams.MATCH_PARENT;
}
super.addView(child, params);
}
}
Run Code Online (Sandbox Code Playgroud)