Home android navgationdrawer and tabs

navgationdrawer and tabs

Author

Date

Category

I ask the Council. Made a navgationdrawer on fragments, now you need to make tabs so that each tab specifies a fragment from the menu list, and when you select the Menu item, the active tab is highlighted. How to do this please tell me.


Answer 1

You will need to implement double navigation. That is what you have chosen in the side menu, the same will be in tabs. It all depends on how you created your side menu, or the studio helped you or you yourself wrote everything. In any case, you will have an XML file or a place in the XML file that will be responsible for outputting the contents of the selected fragment, here for example Website which describes the creation of a side menu, and there is a markup:

& lt;! - This Drawerlayout Has Two Children At The Root - & gt;
& lt; android.support.v4.widget.drawerLayout
  XMLNS: Android = "http://schemas.android.com/apk/res/android"
  XMLNS: App = "http://schemas.android.com/apk/res-auto"
  Android: id = "@ + ID / Drawer_Layout"
  Android: layout_width = "Match_Parent"
  Android: layout_height = "Match_Parent" & gt;
  & lt ;! - This linearlayout displays the contents of the screen - & gt;
  & lt; linearlayout
    Android: layout_width = "Match_Parent"
    Android: Layout_Height = "Match_Parent"
    Android: Orientation = "Vertical" & gt;
    & lt;! - ActionBar is displayed from above - & gt;
    & lt; include
      layout = "@ layout / toolbar"
      Android: layout_width = "Match_Parent"
      Android: layout_height = "wrap_content" / & gt;
    & lt;! - Basic content View, where fragments are loaded - & gt;
    & LT; FrameLayout
      Android: id = "@ + ID / FlContent"
      Android: layout_width = "Match_Parent"
      Android: layout_height = "match_parent" / & gt;
  & lt; / linearlayout & gt;
  & lt;! - Navigation Drawer, which appears on the left - & gt;
  & lt;! - Note that `Android: Layout_Gravity` You need to install in 'Start' - & gt;
  & lt; android.support.design.widget.navigationView
    Android: id = "@ + id / nvview"
    Android: layout_width = "wrap_content"
    Android: Layout_Height = "Match_Parent"
    Android: Layout_Gravity = "Start"
    Android: Background = "@ Android: Color / White"
    App: Menu = "@ Menu / Drawer_View" / & gt;
& lt; /android.support.v4.widget.drawerlayout>

In this piece:

& lt ;! - This linearlayout displays the contents of the screen - & gt;
  & lt; linearlayout
    Android: layout_width = "Match_Parent"
    Android: Layout_Height = "Match_Parent"
    Android: Orientation = "Vertical" & gt;
    & lt;! - ActionBar is displayed from above - & gt;
    & lt; include
      layout = "@ layout / toolbar"
      Android: layout_width = "Match_Parent"
      Android: layout_height = "wrap_content" / & gt;
    & lt;! - Basic content View, where fragments are loaded - & gt;
    & LT; FrameLayout
      Android: id = "@ + ID / FlContent"
      Android: layout_width = "Match_Parent"
      Android: layout_height = "match_parent" / & gt;
  & lt; / linearlayout & gt;

You need to display here except Framelayout also TabLayout in which I will be your tabs. Or if the studio helped you in creating a menu (this means that you initially choose the type of layout type corresponding to the side menu), then the studio creates an XML file that will show you the contents of your screen, and it will already be necessary to post TabLayout .

And then everything is extremely simple: there is a master class in which the logic of working with the side menu is implemented, and there is a markup that refers to the side menu and the content content of the screen. You choose the menu item and the tab that you need. This is the first option, and it seems to me more correctly in logic. There is a second option – in each fragment, in each other, in each other, also TABLAYOUT and mark the fragment you need by transmitting via Bundle some identifier of the selected fragment. But you must remember that you have two kinds of navigation, and therefore you need to mark the selected fragment already in two places so that it does not work so that one fragment is selected and the indication relates to another fragment.

p.s. If someone notices an error or inaccuracy, I will be glad if you specify a problem 🙂

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions