How to inflate new layout on custom navigation drawer when, for example, I click another button in main activity? Is that possible? I havent found any function like beforeOpenDrawer or etc. Or should I construct 4 seperate drawers?
Thank you for your answers
We managed that using fragments. Our DrawerLayout contains a FrameLayout in which we put a "menu" fragment. Some clicks replaces the "menu" fragment by a "submenu" fragment.
I'm not sure I get what you mean.. but if what you want is:
. To create a navigation drawer with custom layout (not just list view) then it is possible.
. Or if you having multiple buttons or radio buttons inside the drawer layout and you need for example to listen for their onClick events … you only write the code once inside the main activity that inflate the left or right drawer.. I've tried something like that but I was using fragments not activities.
Related
The structure of the app is one Activity and multiple Fragments(+ 20).
The Activity has a Toolbar with a title and back button that i used in multiple Fragments.
Then there is two more types of Toolbars that i use inside multiple Fragments, one contains an EditText and the other one is an Expandable Toolbar.
An example would be:
Fragment A: Uses Toolbar from Activity. Show that one, hide if another is showing.
Fragment B: Has a Toolbar of it own, now i need to hide the Activity toolbar.
What would be the correct approach to show/ hide the correct toolbar?
Things i tried:
Using onDestinationChangedListener checking the id of the fragment and show/ hide the correct toolbar. The problem here is that it cause the screen to flicker and i have to check for every id.
toolbar.isVisible = destination.id in listOf(id1, id2...)
Hide or show the correct Toolbar from the Fragment. But then i need to set the toolbar on every Fragment.
(requireActivity() as MainActivity).showToolbar(true)
Removing the Activity Toolbar and creating a new one inside every Fragment. But i don't know if the best way and if it is expensive to constantly inflate the Toolbar.
I'm trying to create a app that navigates in the same way movie pass app does. At the button it has 3 buttons that stay there and a new Activty comes up when you press the buttons.
I could put these buttons on all 3 activtes, but then if I make a code change to the buttons it must be changed in three places.
Two options could help with this. 1) Use a fragment for the content shown above the three buttons so you just have a single activity, and the buttons change which fragment is shown. 2) If you are using a BottomNavigationView or some other view that takes a listener you can create your own OnNavigationItemSelectedListener implmentation that handles all the logic for what happens on button presses. Then that code is in a single place, and you can use that listener in all three activities.
BottomNavigationView navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(new MyNavigationListener());
Use fragments with bottom navigation view it will sortout your problem.
if you use activities instead of fragments then you need to create bottom navigation view for each activity. it will increase your code length & complexity.
If you don't have idea how to use fragments with bottom navigation view. Please follow below link.
https://www.androidhive.info/2017/12/android-working-with-bottom-navigation/
I hope it will help you :)
I am trying to make an App on android. I have made the slide in menu bar like the one shown in the the picture below. The blue bar. Now what I want is that my every screen should show the same menu options. Not those with the back button. How do I do that? Should I make one header and call that in every class? Right now I have an Activity and everything else is a fragment.
I can post my code here as well.
make a Parent Activity and make this acion bar in it.inherit your all activities from this parent activity and just remove setContentView(R.layout.layoutname) from your child activity.
this works in your scenario when you are using fragments so you don't need the layout for activity. so your fragment container would be your parent activity..
Is it possible to disable an activity elements when it loads a fragments?
I have a program which has an activity and two fragments. I put a container in activity. When I put two buttons in activity and load each fragment by clicking the button, fragment loads on the activity, but when I click in the position of buttons which are under fragment(or in the large screen next to it), they do some actions, however I don't like it. The buttons should not be clickable.
As a simple solution I create a third fragment and put my buttons in it and load it as a default view in the activity.
I was wondering is it possible to do this without using third fragment.
If you do not want clicks to propagate to below layers you can specify android:clickable="true".
In your case define android:clickable="true" in the bottom layout of your fragments layout xml file to stop any clicks to the activity below.
mach's solution is great, but i can suggest a solution that will be helpful if you want to do more actions in the future than just disabling buttons.
You can simply have your activity implement an Interface "OnFragmentLoaded" for example which has a single method onLoaded()
and in your fragment in your onAttach(Activity ac) method you can do the following
((OnFragmentLoaded) ac).onLoaded()
and you activity would implement onLoaded() to do what ever you want
I need to create an activity with an ActionBar, so that if you press the action bar buttons, the contents of the activity display the same information in different layout (one is a pie chart and the other a listview).
I don't want to use tabs or a viewpager, so what would be the best way to do this?
Build each view in a separate fragment, and use the actionbar buttons to set the current visible fragment.