Rotate icon ic_drawer in NavigationDrawer - android

Does anyone know how to turn 180 degrees icon ic_drawer in NavigationDrawer after clicking on the drop-down menu?
Currently, after expanding the Menu icon animates to the left - I would like to animating to the right (or the other way around than it is).
Sorry for my English.

you have to use Toolbar which is introduced in support 21+
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mtoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primary" />
also add dependencies in your project .
The last thing to use ActionBarDrawerToggle in your class.
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(MainActivity.this,
mDrawerLayout,mToolbar,"Drawer opentitle","Drawer closetitle");
Constructor's parameter need toolbar object ,so you have to use Toolbar.
check this out ToolBar

Related

Toolbar doesn't flip the custom navigation icon arrow when switching to right-to-left layouts(Arabic)

I am using right to left support for my app. I have a custom arrow set to toolbar as the navigation icon. When I switch to arabic language, everything aligns to right including the toolbar custom navigation arrow. But the problem is the custom navigation icon is not flipping, that is it should be pointing to the right instead of left(default). This works fine with the default indicator if I dont specify any navigation icon. Have anyone encountered this?
Any solution?
Here is my code for the toolbar
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:elevation="0dp"
app:navigationIcon="#drawable/ic_back"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:logo="#drawable/ic_logo"
android:gravity="center_vertical|start"
>
in Activity
Toolbar toolbar = (Toolbar) findViewById(R.id.tb_venue_filter);
setSupportActionBar(toolbar);
setDisplayHomeAsUpEnabled(true);
If you are on android API 21+, you can just flip your icon by adding android:autoMirrored="true" to your vector icon or layer-list XML icon, this will alleviate the hasle of adding it to every toolbar manually, but if you want to support 21- versions you will have to go with the accepted answer.
This is a feature of the Drawable, not so much the Toolbar.
Try with:
toolbar.getNavigationIcon().setAutoMirrored(true);

how to make hamburger menu fully visible

by default half of hamburger is shown, as seen at the top left corner of the screenshot. I want to display full hamburger. code is taken from https://developer.android.com/training/implementing-navigation/nav-drawer.html. how can I do this?
Seems you are using very old technique to create Navigation Drawer. Its around 4 years old code and seems perfect regarding old version.
FYI, previously this kind of UI was done using DrawerLayout with ListView. But now android itself officially introduced sliding panel menu by introducing a newer concept called Navigation Drawer in which we combine DrawerLayout and NavigationView to achieve the desired output.
How to make hamburger menu fully visible?
SOLUTION:
Use AppCompatActivity instead of Activity and use AppCompat theme to achieve your desired output.
Use NavigationView instead of ListView.
Here is an example of NavigationView:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Your contents -->
<android.support.design.widget.NavigationView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/my_navigation_items" />
</android.support.v4.widget.DrawerLayout>
Here is a very good tutorial: Android Sliding Menu using Navigation Drawer
Hope this will help~

Don't show back button on android toolbar

Hi am developing an android application which has a toolbar and hamburger icon to open drawer. I have written below to implement toolbar.
xml file:
<android.support.v7.widget.Toolbar>
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
Java file:
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
((AppCompatActivity)getActivity()).getSupportActionBar().setHomeButtonEnabled(true);
When I click on drawer layout, fragment opens and hamburger button changes to back arrow button.
I don't want this back arrow button. I want that irrespective of which fragment is selected there should always be hamburger icon.
remove this if you don't want any icon:
((AppCompatActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
If you want to set custom icon then add this:
((AppCompatActivity)getActivity()).getSupportActionBar().setHomeAsUpIndicator(R.mipmap.backarrow);
Set your icon in the toolbar, the example is using the default arrow:
mToolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
And to hide, and show:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

Disable navigation icon riple effect in toolbar

Not sure what you call the round effect when you click to go back to previous activity in my case (arrow back icon) but i like to disable that.
This is the code that puts it on the toolbar, but i cant seem to find (if there is) an option to disable that round effect when clicked.
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
mToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back));
Like this round effect buttons produce in toolbar's when pressed. I presume a Material design effect.
Thanks
By changing in your theme you can achieve that. Remove <item name="android:background">#color/toolbar</item> from your theme defined in style.
Follow this stack-overflow link.
Use this in your layout
<android.support.v7.widget.Toolbar
android:id="#+id/yourToolbarId"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/yourId"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_width="wrap_content"
app:layout_height="wrap_content"
app:minHeight="?attr/actionBarHeight"
app:minWidth="?attr/actionBarHeight"
android:src="#drawable/ic_arrow_back"/>
</android.support.v7.widget.Toolbar>
and getSupportActionBar().setDisplayShowHomeEnabled(false); in conjunction
and dont use this
mToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.ic_arrow_back));
Also you have to manually set your click listener to perform specific action you need when it is pressed.
Use false instead of true
getSupportActionBar().setDisplayShowHomeEnabled(false);

Navigation Drawer Notification Icon without Actionbar

In my application I do not want to use the actionbar or toolbar as my app is fairly simplistic and having one of those two would clutter my application. I know when using an actionbar with a navigation drawer there is an icon on the top left to show the drawer exists; however, I want a small notification icon in the middle of the screen to show that the drawer exists. Perhaps a clear arrow? Is this possible? I can not find any documentation on how I would approach doing this. Thank you.
Edit:
I do not want to use ANY type of action bar
Update 2
You can wrap your indicator in a RelativeLayout.
<RelativeLayout android:layout_width="match_parent"
android:layout_width="match_parent"/>
<MyIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_width="match_parent"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"/>
<OtherView android:layout_width="match_parent"
android:layout_width="match_parent"/>
</RelativeLayout>
Update
Use FloatingActionButton from design library.
If you use a toolbar you can set a custom icon. Here is another post doing something like that: Custom icon in Android toolbar
You can use custom action bar in your app that can be customized according to your need.
Refer this link Custom Action Bar

Categories

Resources