更改左侧的ToolBar默认图标

cub*_*beb 5 java xml android android-toolbar

我目前在顶部使用工具栏,并希望用主页按钮替换默认的后退按钮.但是当我添加项目时,它总是添加到右边.我没有看到任何layout_gravity选项可供选择.有没有办法做到这一点?

主要活动

Toolbar toolbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_delete);

    toolbar = (Toolbar)findViewById(R.id.app_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle("                Testing");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.home_icon_empty, menu);
    return true;
}
Run Code Online (Sandbox Code Playgroud)

home_icon_empty.xml

<item
    android:id="@+id/homepage"
    android:orderInCategory="100"
    android:title="HOME"
    android:icon="@drawable/home_icon"
    app:showAsAction="always"
    />

<item
    android:id="@+id/homepage1"
    android:orderInCategory="200"
    android:title="HOME"
    android:icon="@drawable/home_icon"
    app:showAsAction="always"
    />
Run Code Online (Sandbox Code Playgroud)

activity_main.xml中

<include
        android:id="@+id/app_bar"
        layout="@layout/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)

app_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary">

</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)

当前工具栏输出:

在此输入图像描述

预期的工具栏输出:

在此输入图像描述

新编辑后的图像:

在此输入图像描述

Dei*_*zan 9

设为NavigationIcon:

Drawable drawable = ContextCompat.getDrawable(context, R.drawable.your_drawable)
toolbar.setNavigationIcon(drawable);
setSupportActionBar(toolbar);
Run Code Online (Sandbox Code Playgroud)