¿Es posible tener tanto atrás y botón de menú en la barra de herramientas de Android?

En la aplicación iOS Amazon, implementaron el botón de la parte posterior y del menú juntos. ¿Es posible implementar lo mismo en Android?

Aplicación de Amazon iOS

Puede crear un diseño de barra de herramientas personalizada en XML como

<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> 

A continuación, configure a los oyentes para que realicen tareas como openDrawer y goto a la pantalla anterior.

 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); } }); 

Puede crear una barra de herramientas con un diseño personalizado como este:

 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize"> <ImageView android:id="@+id/backButton" android:background="@drawable/ic_back_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/hamburgerButton" android:background="@drawable/ic_home_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/logo" android:background="@drawable/logo" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </android.support.v7.widget.Toolbar> 

Si quieres algo especial crearlo por su cuenta 🙂

Si está utilizando la última biblioteca de diseño es posible crear su panel de barra de herramientas personalizada y agregar cualquier elemento que desee allí.

Yo estaba logrando ese comportamiento de esta manera:

main_activity.xml

 <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"> <!-- this is top bar where you need to add both drawer toggle and back button--> <include layout="@layout/app_bar_navigation" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- Content of sliding menu--> <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="end" android:background="@color/primary_blue_dark" android:fitsSystemWindows="true"> <!-- Custom menu list. Feel free to customize it as listview--> <ListView android:id="@+id/lv_menu" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.design.widget.NavigationView> 

layout/app_bar_navigation.xml

 <?xml version="1.0" encoding="utf-8"?> <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:fitsSystemWindows="true" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="@dimen/nav_header_size_pre5" android:background="@color/primary_blue_dark" android:padding="6dp"> <!-- This is where you need to place those items. I had title and imageview there. You may add anything--> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:layout_centerHorizontal="true" android:gravity="center"> <ImageView android:layout_width="wrap_content" android:layout_height="match_parent" android:src="@drawable/ic_logo" android:adjustViewBounds="true"/> <TextView android:id="@+id/tv_app_logo" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="@string/app_name" android:layout_marginLeft="@dimen/activity_horizontal_margin" android:textColor="@color/primary_yellow" android:textSize="@dimen/middle_text" android:gravity="center"/> </LinearLayout> <ImageView android:id="@+id/iv_drawer_open" android:layout_width="wrap_content" android:layout_height="match_parent" android:src="@drawable/ic_drawer_toggle" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:tint="@color/primary_white"/> </RelativeLayout> <!-- This is main content--> <include layout="@layout/content_navigation" /> 

Sí absolutamente posible sólo tiene que ocultar la barra de herramientas predeterminada haciendo lo siguiente en su Styles.xml :

  <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 

Entonces usted tiene que crear su propio archivo xml de la barra de herramientas vamos a nombrarlo custom_toolbar.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="?attr/actionBarSize" app:contentInsetLeft="0dp" app:contentInsetStart="0dp"> <ImageView android:id="@+id/back_button" android:background="@drawable/back_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/menu_button" android:background="@drawable/menu_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/toolbar_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginRight="10dp" android:textColor="@android:color/black" android:textSize="@dimen/actionbar_textsize" android:textStyle="bold" /> </android.support.v7.widget.Toolbar> 

Entonces usted tiene que agregar esa barra de herramientas en su barra de herramientas de la actividad como abajo

  <RelativeLayout 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" tools:context="betasoft.com.blankblank.ui.ui.activity.SignUp"> <include android:id="@+id/toolbar" layout="@layout/custom_toolbar" /> <FrameLayout android:id="@+id/main_data" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/toolbar /> </RelativeLayout> 

Entonces usted puede acceder a la barra de herramientas en su actividad como:

  Toolbar mToolBar; ImageView mToolBarBack,mToolBarMenu; TextView mToolBarTitle; //Inside onCreate mToolBar = (Toolbar) findViewById(R.id.toolbar); mToolBarBack = (ImageView) mToolBar.findViewById(R.id.toolbar_back); mToolBarTitle = (TextView) mToolBar.findViewById(R.id.toolbar_title); mToolBarMenu= (TextView) mToolBar.findViewById(R.id.menu_button); 

// a continuación, crear un método público como el de abajo para que pueda acceder al contenido de la barra de herramientas en cualquier fragmento

  public void setActionBarTitle(String title) { mToolBarTitle.setText(title); } 
  • Actualizar el contenido de las pestañas de Android Sherlock
  • Tamaño de la imagen de fondo para dispositivos móviles
  • Error StackOverflow, excepción View.inflate
  • Error "No se puede crear instancias de actividad"
  • CSRF en aplicaciones móviles
  • ¿Incrustar un emulador móvil en un sitio web?
  • ¿Cómo lograr alta seguridad en aplicaciones móviles?
  • Evento Javascript para el lanzamiento del navegador móvil o dispositivo despertador
  • Mensaje de error: emulator-arm.exe ha dejado de funcionar
  • ¿Cómo obtienes MCC y MNC del teléfono en Android?
  • Chrome en Android no amplía el elemento de encabezado en el cambio de orientación
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.