B4A Library StdActionBar - Another ActionBar library

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jan 16, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    StdActionBar (Standard ActionBar) library is based on the native ActionBar API, therefore it is only supported by Android 4+.

    StdActionBar / StdViewPager tutorial: ActionBar / Sliding Pages tutorial

    The share of Android 2.x devices is dropping and currently (January 2014) it is only 24%.

    This library allows you to add tabs and dropdown list to the action bar:

    upload_2014-1-16_17-20-37.png upload_2014-1-16_17-21-7.png

    The attached example demonstrates both modes. You should change the navigation mode to see the two modes.

    List mode

    Adding a list is very simple. You set the NavigationMode:
    Code:
    bar.NavigationMode = bar.NAVIGATION_MODE_LIST
    Add the items:
    Code:
    bar.SetListItems(Array As String("Dropdown 1""Dropdown 2""Dropdown 3"))
    And handle the event:
    Code:
    Sub bar_ListItemSelected (Index As Int, Value As String)
       
    Log("Selected value: " & Value)
    End Sub
    Tabs mode

    Unlike TabHost, the tabs do not hold any views. You are responsible for switching the layout based on the selected tab.

    The first step is to set the navigation mode:
    Code:
    bar.NavigationMode = bar.NAVIGATION_MODE_TABS
    Then we add the tabs:
    Code:
    bar.AddTab("Tab 1")
    bar.AddTab returns a StdTab object. We can use it to modify the tabs:
    Code:
    bar.AddTab("Tab 1").Tag = panel1
    bar.AddTab(
    "Tab 2").Tag = panel2
    'Add icon to tab 3
    Dim tb As StdTab = bar.AddTab("Tab 3")
    tb.Tag = panel3
    Dim bd As BitmapDrawable
    bd.Initialize(
    LoadBitmap(File.DirAssets, "ic_small.png"))
    tb.Icon = bd
    In the above code we add three tabs and use the tabs tag property to store a panel in each tab. Later we will use these panels to switch the layout.

    When the TabChanged event is raised we clear the current layout and show the new layout.
    Code:
    Sub bar_TabChanged(Index As Int, STab As StdTab)
       
    Activity.RemoveAllViews
       
    Dim pnl As Panel = STab.Tag
       
    Dim height As Int
       
    If 100%y > 100%x Then
         height = 
    100%y - 48dip 'fix for the additional tabs height
       Else
         height = 
    100%y
       
    End If
       
    Activity.AddView(pnl, 00100%x, height)
       
    If pnl.NumberOfViews = 0 Then
         pnl.LoadLayout(Index)
       
    End If
    End Sub
    Note that the attached example uses the Holo.Light theme. This is done with this manifest editor line:
    Code:
    SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")
    V1.52 is released. Fixes an incompatibility with Android 5.0. Note that the ButtonClicked event will not work on these devices.

    You should use Activity_ActionBarHomeClick event instead.
     

    Attached Files:

    Last edited: Jul 27, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

    The ability to change tabs with a swipe gesture will be added next week (ViewPager).
     
    Sytek and FireDroid like this.
  3. hugorinen

    hugorinen Member Licensed User

    Hi !

    Thanks for this library, but what if I want to remove an actionbar item ?
     
    liumin99 likes this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    Which type of item?
     
  5. hugorinen

    hugorinen Member Licensed User

    Buttons on the Action Bar added with "Activity.AddMenuItem3"
     
  6. merlin2049er

    merlin2049er Well-Known Member Licensed User

  7. GMan

    GMan Well-Known Member Licensed User

    I got a "warning" when compiling, that the sample code is written for a newer version ?
    Means that its only for IDE > 2.71 useable
     
  8. socialnetis

    socialnetis Active Member Licensed User

    Hi Erel, is this the same bar that use Gmail and youtube? For example:
    [​IMG]

    The Logo is a button that opens a left panel, and for example the search button uses the App Name Label to make the search.
     
  9. cbc551

    cbc551 Member Licensed User

    You can use this library in 2.71 version. The problem are the .bal files that are created with the newest version. You must delete them and create them again to work.

    Another question, I've been reading this tutorial to change the color of the action bar:

    http://developer.android.com/guide/topics/ui/themes.html

    but I have not been successful. This library supports the color change?

    Thanks!
     
  10. Erel

    Erel Administrator Staff Member Licensed User

  11. woniol

    woniol Active Member Licensed User

    Hi,
    This ActionBar looks nice, would it be possible to add support for 'home/back' and drawer indicator icon to use with drawer lib.
    This icons are placed left to app icon.

    Can you also give an example of color/backgroun how to customize it.
     
    Last edited: Jan 17, 2014
    FireDroid likes this.
  12. corwin42

    corwin42 Expert Licensed User

    I'm currently playing with it (again).

    The problem is that there is no event (in B4A) when home/up is pressed so you can't open/close the drawer when the home button is pressed.

    Changing the up indicator is a bit tricky with Android < API 18 but I created a small library that handles this. I will talk to Erel if he wants to add it to the StdActionBar library or if I should create an ActionBarHelper library.
     
  13. socialnetis

    socialnetis Active Member Licensed User

    Oops, here it is:

    [​IMG]
     

    Attached Files:

  14. Erel

    Erel Administrator Staff Member Licensed User

    This is the same bar. This library will be soon updated and will allow you to handle the logo click event (as well as other improvements).

    You can use this library: jfeinstein10 SlidingMenu library
    or one of the similar libraries to implement a side menu.
     
  15. Erel

    Erel Administrator Staff Member Licensed User

  16. woniol

    woniol Active Member Licensed User

    Hi,
    the view pager works fine, but when I add more than three tabs in landscape, the tab are changed to drop-down.
    This drop down isn't synchronized with view pager.
     
  17. Erel

    Erel Administrator Staff Member Licensed User

  18. woniol

    woniol Active Member Licensed User

    That's the example i try it with, the only deference is that i add 6 tabs instead of 3.
    The dropdown is not updated with page slide, it works fine when i select item form dropdown i get the right tab displayed.

    I try it on real device with android 4.1.2
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Try to set SelectedIndex in your code. Does it affect the selected item?
     
  20. woniol

    woniol Active Member Licensed User

    Works fine when tabs a visible, but does not work with dropdown.

    To be strict the problem is when the amount of tabs is too big to fit in the bar and they are changet do dropdown. Not in typical List Mode
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice