I want my button that opens navigation drawer to be displayed on the toolbar first in the left but I am unable to place it before the title. I tryed set android:gravity="left"
but that does not seem to help. Can anyone help me with this?
Here is my toolbar 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>
It was mistake to do it manually. I should use ActionBarDrawerToggle
.
You can use one of the following two methods:
First, in 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" />
Second, inside activity:
@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
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.