最佳答案
您可以在 XML 中创建自定义工具栏设计作为
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize">
<ImageView
android:id="@+id/backButton"
android:background="@drawable/back_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/homeButton"
android:background="@drawable/menu_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
然后设置监听器来执行诸如打开抽屉和转到上一屏幕等任务。
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
ImageView homeButton = (ImageView) toolbar.findViewById(R.id.homeButton);
homeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
drawerLayout.openDrawer(GravityCompat.START);
}
});
关于android - Android工具栏中是否可以同时拥有后退按钮和菜单按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36037273/