Best way to reuse footer in Android

I am trying to implement a menu in the application footer similar to the Engadget application. As far as I understand, getting a standard TabLayout to work this way is not trivial (if at all possible?).

As I see quite a few applications using this interface paradigm, I would suggest that there is a smart way to do this. I am currently defining a layout by adding an include line at the end of each layout. This works fine with respect to rendering, but I have to add onClickListeners for each action. can we define clickListener via xml?

To summarize my question: What is the best way to implement common footer navigation in a few steps?

+7
android footer menu
source share
3 answers

You can make all your actions flow from a common base class that extends Activity and puts a method to create a menu there. Use a RelativeLayout as the main container, stick to the horizontal LinearLayout at the bottom (layout_alignParentBottom = "true"), and then align your main content container (any type of layout you want for a specific activity) above that. Using android: weight on what you put in your menu (for example, ImageButton) and then android: weightSum in the menu container, they will be evenly distributed. So, if you have four ImageButtons with android: weight = "1", and the LinearLayout containing them has android: weightSum = "4", you should be good.

So, TabContentActivity can extend the Activity, and then all your actions extend the TabContentActivity. TabContentActivity has onCreate, which calls super.onCreate, and then calls the private method to create the menu. Then, when your derived classes are called super.onCreate in their own onCreate, your tabs are created. You can have an Enum in a TabContentActivity representing each tab, with a local variable of this type Enum to indicate which tab is highlighted.

Do not listen to people telling you not to do it this way. If you want this user interface, do not limit yourself to the environment in which you work. Just as you have answers telling you that is not the “right way to do this in Android,” you also have two votes.

+7
source share

Here is a long shot, and I never tried to see if it works:

  • Create a custom class that contains onClick methods for elements in the footer. import this class in every Activity you have;
  • Use android:onClick in the attached XML file with values ​​pointing to methods in this class.

Now I'm not sure that this class should be created in every Activity , or if you can use its methods as static, but something like this should work, and this is better than adding listeners to each activity.


In my opinion (and I emphasize that this is only my opinion), this interface paradigm, as you call it, is a poor attempt to copy the iPhone. This paradigm is very popular on the iPhone, mainly because it has only one button. I even hate the Engadget app for this (and again, it's copied from the iPhone app) - it distracts the screen real estate.

In short, my advice is: use the MENU button . p>


Last note: it has never been played with TabLayout , but if you want a separate Activity on each tab, then I am 99.9% sure that you can not do this (you can not insert whole actions in any view or ViewGroup ). TabLayout only contains children of Layout s, not actions. In addition, with TabLayout you can say goodbye to the BACK button (are you going to spend another button to copy the user interface from the iPhone?) - if you do not plan to redefine it, in which case you can say goodbye to your users.

0
source share

Not sure if this idea works,

Set TabLayout1 on the footer, but set it so that only the tabs are displayed, not the content (which would be below the footer in invisible space).
Then add a second view to the rest of the screen, and you can switch between them. If you set the second layout (top) as the TabLayout2 tab and bind the tabs to "Activities", you can share this view between actions. Also note that you need to set TabLayout2 on top so that the tabs are not visible only in the content area. I think that with some additions it is possible to solve.

0
source share

All Articles