I have an application with Activity, Fragment inside activity, Toolbar and Navigation Drawer.
I need a Toolbar will hiding when I scroll content of fragment.
Following manual I need to put ToolBar and scrollable content inside same XML file. But my scrollable content placed in Fragment and ToolBar placed in Activity. How to implement collapsing Toolbar?
You need to use CoordinatorLayout
Try to use this guide. There's good explanation
Related
I'm creating a single activity applicatition. Inside Activity there is a BottomNavigationView
with NavHostFragment. Bottom navigation view comprise of multiple menu items.
For easy to explain lets say there are three fragments "FragmentOne", "FragmentTwo", "FragmentThree"
each fragment have a different Toolbar. As a example "FragmentOne" is haveing a Toolbar with CollapingToolbarLayout, and "FragmentTwo" has a Normal Toolbar Design and "FragmentThree" has a toolbar with Image.
I have included different design Toolbars in each fragment and the BottomNavigationView is inside Activity.
Where select each bottom navigation menu, fragments are navigating correctly but content is showing fade in animation/transition.
I have set the app theme as Theme.AppCompat.Light.NoActionBar So now since Toolbar is also inside the fragment content area Toolbar also showing fade in transition.I'm okay with content transition but Toolbar should stay Solid.
Kindly help to me to solve this and feel free to request more information.
I have a CoordinatorLayout that contains a BottomNavigationView and an AppBarLayout with a ToolBar inside of it. (The BottomNavigationView is not inside the AppBarLayout, as doing it breaks the position of the BottomNavigationView).
I need to show/hide the AppBarLayout and the BottomNavigationView programmatically, when certain events happen (e.g. on a fragment's onResume), and so far I've managed setting appBarLayout.setExpanded(true, true) in order to show/hide the AppBar, but I can't figure out how to do the same for the BottomNavigationView, as it does not have any method to show/hide itself.
The behaviour of my BottomNavigationView is app:layout_behavior="#string/hide_bottom_view_on_scroll_behavior", set in the layout xml. How can I get a reference to this behaviour in my code in order to manage its expanded/collapsed state?
Thats code slides up your bottom navigation that are inside of a Coordinator Layout and have a HideBottomViewOnScrollBehavior.
If you are using findViewById just replace that for every binding.
val layoutParams = binding.bottomNavigation.layoutParams as CoordinatorLayout.LayoutParams
val bottomViewNavigationBehavior = layoutParams.behavior as HideBottomViewOnScrollBehavior
bottomViewNavigationBehavior.slideUp(binding.bottomNavigation)
You can hide bottomNavigation view from your fragment container activity. Because of you have bottomNavigation id. and you can access this id from your fragment container activity and also you can get the current fragment instance from your fragment container activity. So from your example if you want to hid bottom navigation from particular fragment onResume() event you can check that which fragment is currently visible from you Fragment container activity and call hide or show bottom navigation.
Remember for hiding or showing bottom navigation use animation.
I am using Navigation Drawer in my App and therefore using fragments for each list item in the drawer. I tried to change the android.support.v7.widget.Toolbar on navigating to each fragment of Navigation Drawer's list item, however it is coming below the already present activity's toolbar instead of replacing it which is what I want.
How do I replace the already present toolbar in ActionBarActivity with fragment's toolbar? Let me know your suggestions...
Since toolbar is a view, you can set the visibility of the Activity's toolbar to hidden, before transition to any fragment.
toolbar.setVisibility(View.GONE);
Then inside the fragment layout you can set Fragment specific toolbar and set it as the actionbar for that fragment.
Now you can use AppCompatActivity.
It doesn't have default toolbar, so you can call setToolbar(Toolbar toolbar) for each fragment.
I've got a toolbar in a view-pager (tabbed toolbar with horizontal swipe navigation) and each tab has its own fragment with a recyler_view. I now want to hide the toolbar when my recyler_view scrolls. In my fragment i added the on scroll-listener and want to call there a method in its activity class to hide the toolbar. The toolbar is created in the activity. How can I call this method from my fragment? or would it be better to implement this hiding method in my fragment itself. But then how can i "contact" my toolbar, that is created in the activity and not in the fragment. I have found solutions, but none of them talks about a recylcer_view in a fragment and view-pager for tabbed navigation.
Would be great if you can help me...
I just had the same problem as you and solved it by using a library ObservableScrollView.
Have a look at ViewPagerTabRecyclerViewFragment.
If you don't want to use a library you still can have a look at how they implemented it as the lib is Open Source
so my ToolBar is in my MainActivity layout, along with a container underneath it for the fragments. All fragments have a ScrollView, I would like to hide the ToolBar when a Fragments scrollview is scrolled. What is the best way around having the fragment and main activity communicate?
To communicate between activity and Fragment, implementing an interface is the best option i know. Read more about it here http://developer.android.com/training/basics/fragments/communicating.html