Changing the ActionBarDrawer checkbox when using the v7 library

I want to use a custom image instead of the default icon used to switch the navigation box in android. How can I do it? Here is an image of what I want to change. enter image description here

+8
android navigation-drawer toolbar
source share
5 answers

Use the code below to set your custom ActionBar toggle button.

mDrawerToggle.setDrawerIndicatorEnabled(false); // mDrawerToggle.setHomeAsUpIndicator(R.drawable.menu_icon); mToolbar.setNavigationIcon(R.drawable.menu_icon); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mDrawerLayout.openDrawer(Gravity.LEFT); } }); 
+6
source share

you can change using style.xml

  <style name="BaseTheme" parent="Theme.AppCompat.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="homeAsUpIndicator">@drawable/menu</item> <item name="android:textColorPrimary">@android:color/white</item> </style> 
+3
source share

@Arya gave a good example using styles.xml:

 <style name="BaseTheme" parent="Theme.AppCompat.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="homeAsUpIndicator">@drawable/menu</item> <item name="android:textColorPrimary">@android:color/white</item> </style> 

You can also do this programmatically:

 public void setTitle(String title, int homeAsUpIndicator) { if (getSupportActionBar() != null) { getSupportActionBar().setTitle(title); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeAsUpIndicator(homeAsUpIndicator); } } 

Then, in your onCreate () method, you can call the setTitle method with up indicator ican as a resource.

NOTE. uses a support action bar with a new toolbar.

0
source share

To change the navigation menu icon, you need to define your image in the ActionBarDrawerToggle object as follows: mDrawerToggle = new ActionBarDrawerToggle (this, mDrawerLayout, YOUR IMAGE_SOURCE HERE, R.string.drawer_open, R.string.drawer_close)

If you find any difficulties, you can comment on this.

0
source share

I used a custom action bar and myself processed the action back. I think this is the best way. PFB xml:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/transparent" android:gravity="center_vertical" android:orientation="horizontal" android:layout_margin="@dimen/outer_padding" > <ImageView android:id="@+id/btnBack" style="@style/back_button_style" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_centerVertical="true" android:src="@drawable/white_arrow" /> <com.example.widgets.CustomTextView android:id="@+id/tvTitleImage" style="@style/actionbar_text_style" android:layout_centerInParent="true" android:layout_centerVertical="true" android:layout_toRightOf="@+id/btnBack" android:padding="@dimen/outer_padding" android:text="@string/requests_text" custom:typefaceAsset="@string/berlin_bold" /> <ImageView android:id="@+id/btnAdd" style="@style/back_button_style" android:layout_width="@dimen/actionbar_menu_icon_dim" android:layout_height="@dimen/actionbar_menu_icon_dim" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/ivSearch" android:src="@drawable/app_icon" /> <ImageView android:id="@+id/ivSearch" style="@style/back_button_style" android:layout_width="@dimen/actionbar_menu_icon_dim" android:layout_height="@dimen/actionbar_menu_icon_dim" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:src="@drawable/app_icon" /> </RelativeLayout> 
0
source share

All Articles