B4A Library StdActionBar - Another ActionBar library

jcesar

Active Member
Licensed User
Longtime User
@jcesar try to add the EditText to a Panel and then add the panel as the custom view. Now try to set the EditText width.

I try, but nothing happens... The panel is not displayed in the actionbar. And if i set the EditText width i get the same NullPointerException error.

I think must be something with layouts... But I dont know if its possible solve with b4a.
 

woniol

Active Member
Licensed User
Longtime User
You should change view size properties after adding it to AB
B4X:
dim edtTeste as EditText
edtTeste.Initialize("")
edtTeste.Hint = "Search !"
edtTeste.TextColor = Colors.White
Dim jo As JavaObject = actionBar
jo = jo.GetField("bar")
jo.RunMethod("setDisplayShowCustomEnabled", ArrayAsObject(true))
jo.RunMethod("setCustomView", ArrayAsObject(edtTeste))

edtTeste.Width = 100dip
 

jcesar

Active Member
Licensed User
Longtime User
Thanks. I will try this...
 

jcesar

Active Member
Licensed User
Longtime User
Hi.

Its possible load a scrollview into the viewpager panels ?

When the device is in landscape mode, many of my views are out of the screen, so i need a vertical scroll to access all the views.
 

Inman

Well-Known Member
Licensed User
Longtime User

How can I put a Switch View on this Standard Actionbar?
 

woniol

Active Member
Licensed User
Longtime User


Should it work for 3 or more tabs?
When I try to add it to third tab i get this in log:
java.lang.IllegalArgumentException: No view found for id 0x6 for fragment MyMapFragment{42975b68 #0 id=0x6}
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
It should work with any number of tabs:


B4X:
Sub Process_Globals

End Sub


Sub Globals
  Dim mFragment As MapFragment
  Dim gmap As GoogleMap
  Dim MapPanel As Panel
  Dim bar As StdActionBar
  Dim vp As StdViewPager
End Sub

Sub Activity_Create(FirstTime As Boolean)
  MapPanel.Initialize("")
  bar.Initialize("bar")
  bar.NavigationMode = bar.NAVIGATION_MODE_TABS
  bar.AddTab("Map")
  bar.AddTab("Red panel")
  bar.AddTab("Blue panel")
  Dim h As Int = CalculateHeight(True, False)
   
  vp.Initialize("vp", 3, 100%x, h)
  MapPanel.Initialize("")
  Activity.AddView(vp.AsView, 0, 0, 100%x, h)
  vp.Panels(1).AddView(MapPanel,0, 0, 100%x, h)
  vp.Panels(0).Color = Colors.Red
  vp.Panels(2).Color = Colors.Blue
  If mFragment.IsGooglePlayServicesAvailable = False Then
  ToastMessageShow("Google Play services not available.", True)
  Else
  mFragment.Initialize("Map", MapPanel)
  End If
End Sub

Sub CalculateHeight (TabsMode As Boolean, SplitEnabled As Boolean) As Int
  If 100%x >= 480dip Then
  Return 100%y
  Else
  Dim fix As Int
  If TabsMode Then fix = 48dip
  If SplitEnabled Then fix = fix + 48dip
  Return 100%y - fix
  End If
End Sub

Sub VP_PageSelected (Position As Int)
  If bar.SelectedIndex <> Position Then bar.SelectedIndex = Position
End Sub

Sub bar_TabChanged(Index As Int, STab As StdTab)
  If vp.currentPage <> Index Then  vp.ScrollTo(Index, False)
End Sub
 

woniol

Active Member
Licensed User
Longtime User

Ok, but You still add it do the second one:
B4X:
 vp.Panels(1).AddView(MapPanel,0, 0, 100%x, h)
  vp.Panels(0).Color = Colors.Red
  vp.Panels(2).Color = Colors.Blue

please try:
B4X:
 vp.Panels(2).AddView(MapPanel,0, 0, 100%x, h)
  vp.Panels(0).Color = Colors.Red
  vp.Panels(1).Color = Colors.Blue
 
Last edited:

woniol

Active Member
Licensed User
Longtime User
Actually it is in the second panel not the first (the commands order is not important).

I see the error you get if it is in the last page. I'm not sure why it happens. Try it on any of the other panels and it will work.

Looks like it only works with
B4X:
p.Panels(0).AddView(MapPanel,0, 0, 100%x, h)
or
B4X:
p.Panels(1).AddView(MapPanel,0, 0, 100%x, h)

not above it
 

woniol

Active Member
Licensed User
Longtime User
Actually it is in the second panel not the first (the commands order is not important).

I see the error you get if it is in the last page. I'm not sure why it happens. Try it on any of the other panels and it will work.

Looks like it only works with
B4X:
p.Panels(0).AddView(MapPanel,0, 0, 100%x, h)
or
B4X:
p.Panels(1).AddView(MapPanel,0, 0, 100%x, h)

not above it

That's it. Thank You very much for your help.
 

jcesar

Active Member
Licensed User
Longtime User


Hi Erel

The app crashes when i put the map in the last "tab" (vp.panels(2)). This code only works when the mapview is in the first or second tabs.

Maybe i doing something wrong...
 

Inman

Well-Known Member
Licensed User
Longtime User

In most Android apps (including official Google apps like Gmail), there will be a search button on the actionbar, clicking on which will suddenly display a text box right on the actionbar itself for searching. I understand that we can do it with the above code. But if the user clicks the physical (or on screen) back button on his phone, this text box should disappear, restoring the actionbar to it's original form.

Can we do that in B4A?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…