I am implementing Navigation Drawer in my Main Activity. When I load a fragment for the drawer item, the action bar gets overlapped above the fragment.I am required to give a top margin of about 48 dp, so that my views come below the action bar. How can I bring my fragment layout below the ActionBar?
layout_marginTop="?attr/actionBarSize"
use this in your layout it changes in size based on screen configuration automatically
Have a look at this tutorial:
android-sidebar-navigation-drawer-with-icons
Related
I have a main activity with bottom nav and a frame layout to hold each fragment I have made for the numbers of icon in my botton nav. I have a fragment page in which i have a text and want to change the fragment and also the bottom nav icon from the click action on text.
Please refer to below links :
Android new Bottom Navigation bar or BottomNavigationView
How to Code a Bottom Navigation Bar for an Android App
Android Working with Bottom Navigation
In the picture what I want to do.
I have two menu.xml files. How to add the first menu at top app bar and the second at the bottom app bar? Can I do this in one activity or I should create activity with top app bar + fragment with a bottom app bar? Thanks.
So, I solved this problem.
For toolbar on top of the activity I use setSupportActionBar() inflate menu in onCreateOptionsMenu() and processing MenuItem click in onOptionsItemSelected()
For BottomAppBar (new material component) I use bottomAppBar.replaceMenu() in order to set the menu. For processing MenuItem click: bottomAppBar.setOnMenuItemClickListener()
Result
How to add the first menu at top app bar and the second at bottom app
bar? Can I do this in one acivity or I should create Activity with top
app bar + fragment with bottom ap bar?
You'll probably be able to do that with onCreateOptionsMenu() for the top of the Activity, (called Toolbar) then use a NavigationDrawer and another View (Can be a custom view like LinearLayout with ImageViews or etc) or another Toolbar in the bottom.
Or, using custom view and inflating menus by onCreateOptionsMenu().
This might help for two Toolbars in one Activity: https://stackoverflow.com/a/37002188/4409113
Also: https://stackoverflow.com/a/34906999/4409113
In your case (as we can see in the picture), i believe there is a Toolbar at top of Activity, with CoordinatorLayout which has FloatingActionButton in the middle and there will be just inflating in java-kotlin side left.
How to make icon in my Navigation Drawer rectangle like original size?
Yes, by default if you are using menu resource with items to populate Navigation drawer it will have equal width and height.
Alternatively, you can create your own listview with custom list_item for Navigation Drawer and use it to populate your own data with your Custom UI.
Please refer this link to do so : Android Nav Drawer
in my android project, I have set up a navigation drawer. Now, on swiping, the drawer works fine but I have a few problems that I'd liked solved.
There is no drawer icon to the left side of my launcher icon in the action bar. How do you implement that. Also when I click on the action bar icon, the navigation drawer does not slide in.
I would like to change the color of the text of my ListView inside my navigation drawer. I tried changing android:textColor in the xml layout but it didn't work.
I have the drawer_shadow.9.png drawable of the navigation drawer and I tried implementing it using the setDrawerShadow(drawable, gravity); method but it didn't seem to work. In the two parameters I added the drawable and the ListView R.id for the gravity.
That's just about it. Let me know if you need any more info. Thanks in advance.
There is no drawer icon to the left side of my launcher icon in the action bar. How do you implement that. Also when I click on the action bar icon, the navigation drawer does not slide in.
Use ActionBarDrawerToggle.
I would like to change the color of the text of my ListView inside my navigation drawer. I tried changing android:textColor in the xml layout but it didn't work.
If the "xml layout" is the one for the row, it should work. If the "xml layout" is the one for the drawer (where your ListView is), it should not work.
In the two parameters I added the drawable and the ListView R.id for the gravity.
From elsewhere in the DrawerLayout documentation, I think your interpretation of the second parameter is off:
Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right. GravityCompat.START or GravityCompat.END may also be used.
Is it possible to overlay the actionbar with one specific view(i.e sliding drawer)? I know i can make the whole activity full screen and put the action bar on top of it, but i need to slide a sliding drawer on top of the action bar.
You can now layout the action bar as a "toolbar" which behaves in the layout just as any other view, and then you can overlay other views (Using frame layouts, drawer layouts etc).
See the section in here about toolbar:
http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html
As Toolbar is just a ViewGroup, you can style and position it however you want.
Then in your Activity or Fragment, set the Toolbar to act as your Action Bar: