Slide menu display same for all pages Android - android

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..

Related

Trying to create a app that has 3 navigation buttons at the buttom and a new activity comes up when corresponding button is

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 :)

Android: Using fragments

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

Changing navigation drawer layouts

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.

Activity with variable content

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.

Tabs disappears in TabActivity after it goes to other Activities

In my app I have four tabs in the bottom of my main screen. When the user click in one of the tabs in the bottom it open an Activity and the user needs to fill up a form, after the form is done it returns to one of the TabActivities.
Everything works well, except when the form is save its supposed to go to the Activity an show the four tabs in the bottom. The problem is that the tabs in the bottom disappear.
I thought the if Im calling the TabActivity it will always show the tabs that were assign in the XML layout.
Okay you have to go for ActivityGroups. But in later version of android Activity Group is deprecated and hence you have to go for fragments or views. Here are few links which will get you started.
ActivityGroup Example
http://blog.henriklarsentoft.com/2010/07/android-tabactivity-nested-activities/
http://united-coders.com/nico-heid/use-android-activitygroup-within-tabhost-to-show-different-activity

Categories

Resources