[英]Center Toolbar Title in custom toolbar with icons and navigation drawer toggle button
[英]Align Navigation Drawer button in toolbar before title
我希望打开导航抽屉的按钮首先显示在工具栏的左侧,但是我无法将其放置在标题之前。 我尝试设置android:gravity="left"
但这似乎无济于事。 谁能帮我这个?
这是我的工具栏xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="2dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/imageView"
android:src="@drawable/ic_menu_white_24dp"
android:gravity="left"
/>
</android.support.v7.widget.Toolbar>
手动执行操作是错误的。 我应该使用ActionBarDrawerToggle
。
您可以使用以下两种方法之一:
首先,在xml中:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
app:navigationIcon="@drawable/ic_menu_white_24dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
二,内部活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child_swipe);
Toolbar toolbar = (Toobar) findViewById(R.id.toolbar)
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do something here
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.