I'm new to Android development. I get that a NavigationView is an AppBar (i think). What makes these two different? I want to create a custom "appbar/toolbar" with a centered logo and menu/settings button in the top right corner (instead of the standard left) which reveals a drawer.
I was going to ditch the built in appbar/toolbar all together and just create my own somehow and include button overlay which displays a drawer.
What would you do? Navigation view, app bar, or custom toolbar from scratch? I don't know what the standard is or what is acceptable. What is the difference between a navigationview and appbar. Thank you.
edit: I'm slowing realizing that an appbar is one feature within a navigation view, among others like a drawer layout, menu items etc... i think.
1. NavigationView
By using NavigationView, we can bind the menu directly with NavigationView. This is the benefit of the NavigationView. No need to create ListView and adapter with navigation drawer. By default we can get selector of item click. With menu we can change the color of icon of selected menu.
For more details :
1.https://developer.android.com/reference/android/support/design/widget/NavigationView.html
http://www.technotalkative.com/part-4-playing-with-navigationview/
2. AppBar
Appbar is for toolbar with scrolling effect. We can easily give the material design effect.
For more details :
1.https://developer.android.com/reference/android/support/design/widget/AppBarLayout.html
Related
I am using the new Navigation Components library. I have a Navigation Drawer in place that works perfectly fine.
If my user logs in I want to change the menu of the Navigation Drawer. Specifically, I want to change the "Login" item to "Logout" from within a fragment.
All the solutions I found online didn't use Navigation Components. So therefore, they recommended something like this:
// Get the navigationView and swap the menu
NavigationView navigationView = view.findViewById(R.id.nav_view);
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.activity_main_drawer_logged_in);
However, this doesn't seem to work in my case (I cannot get the navigationView from within a fragment). How does one achieve this with Navigation Components?
You can access Activity from Fragment through interface:
Create and interface say LoginSuccessListener
Implements this in your Activity
Inside fragment receive this listener inside onAttach
Use it as you needed to update Navigation Menu
I I need to change the toolbar icon of my main_activity(Navigation Drawer Activity) and replace it with back icon and with a different function(go back).
How can i change different toolbar with different function for all my fragment?
I'd suggest starting a new activity instead.
This way you don't have to modify the drawer icon and touch handling of the icon is also separated. (You would just close your new activity when the up navigation is clicked).
However, if you want to do it all in your current Activity, you need to change the ActionBar / Toolbar icon and override the clickListener of the navigation icon.
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
and
toolbar.setNavigationOnClickListener(yourClickListener);
It is possible to have a Navigation Drawer and a FragmentActivity which has also swiping tabs?
E.g. When I select an item in the menu, a swiping tab view should appear.
To answer your question - yes, it is absolutely possible. Navigation Drawer Swipe Views
Just follow above tutorials and combine them.
I'm implementing NavigationDrawer with ActionBarSherlock and now I'm trying to implement custom icon for opening and closing the drawer. I already set my own icon (white) but I'm not able to get rid of that grey default icon.
in onCreateOptionsMenu I'm doing this:
getSupportActionBar().setDisplayShowTitleEnabled(false); // does not display activity title
getSupportActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.actionbar_background)); // blue background
getSupportActionBar().setIcon(R.drawable.side_menu_button); // white icon
The picture shows difference when navigation drawer is closed (first) and open (second picture).
Is there any way to do it programmatically? Or is there even some way to do it? I hope it is.
Thank you.
EDIT: This is what I'm trying to achieve:
What you are currently doing is setting the icon on the ActionBar, which is different from setting the icon of the ActionBarDrawerToggle, which is what you want to be dealing with. If you look at the documentation (http://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html) and find the constructor, you'll see there's a place to specify a custom Drawable to be used by the toggle.
Usually the Drawer Layout is hidden on the view until the onTouch or onSwipe in is triggered. I'd like to make the drawer layout initially displayed. I also checked out the SlidingLayer Library but
It is more complicated that the new drawer layout that Android has released. In the image below, the blue lines represents the initial drawer that needs interaction which also triggers the opening and closing of the drawer.
My last resort on this it to have a button, on the view that will handle the interaction, but as much as possible I want to have a normal view on drawer layout.
I have seen this on the documentation, not sure what it does:
setDrawerShadow(Drawable shadowDrawable, int gravity)
Set a simple drawable used for the left or right shadow.