B4A Library TabHostExtras

sotik

Member
Licensed User
Longtime User
would be possible to do the tabs titles container horizontal scrollable?, if there are a lot of tabs, the titles can not be shown correctly
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I spent some time tonight with this library and while I went another way with my project I would just like to say great job on this. It is really a great lib.
 

tipallandgo

Member
Licensed User
Longtime User
Is there a way to change the bottom line colors of the TabWidget?

tried this:

B4X:
Dim tb as TabHost
Dim tbe as TabHostExtras
...
Dim cd As ColorDrawable
cd.Initialize(Main.MAIN_COLOR, 0)
tbe.GetTagWidget(tb).StripEnabled = True
tbe.GetTagWidget(tb).LeftStripDrawable = cd
tbe.GetTagWidget(tb).RightStripDrawable = cd

but that does not seem to work.
 

Gary Milne

Active Member
Licensed User
Longtime User
This is a very handy library as the basic methods fall short of the standards of most decent programmers. Things must have changed from the initial posts which recommended using an XML file and the current state for managing the colors of the buttons. I found this a little kludgy and the fact there were only two states (enabled or disabled) was short of what I wanted.

Using TabHostExtras I was able to have three different states Enabled, Disabled and Selected. Here is a simple example to do that.

B4X:
Sub Set_Tab_State(TabName As TabHost, TabEnabled As Boolean, TabNumber As Int )
    Dim TabLabel As Label
    Dim TabMgr As TabHostExtras
   
    TabLabel = TabMgr.GetTagWidget(TabHost1).GetTabLabel(TabNumber)
   
        If TabEnabled = True Then
            If TabName.CurrentTab = TabNumber Then
                TabLabel.TextColor = Colors.Yellow
                TabLabel.TextSize = 10 * Main.Scale
                TabLabel.Typeface = Typeface.DEFAULT_BOLD
            Else
                TabLabel.TextColor = Colors.White
                TabLabel.TextSize = 8 * Main.Scale
                TabLabel.Typeface = Typeface.DEFAULT
            End If
        Else
            TabLabel.TextColor = Colors.LightGray
            TabLabel.TextSize = 8 * Main.Scale
            TabLabel.Typeface = Typeface.SERIF
        End If   
    TabLabel.Invalidate
    TabMgr.setTabEnabled2(TabName, TabEnabled, TabNumber)
   
End Sub

I also change the size of the Font for the currently selected item which looks good.

Hopefully this will be of help to someone.

P.S. The Main.Scale is a multiplier for the Font Size that is the same formula used for the AutoScaling that is shown below.
B4X:
    'Calculate the scale used to scale fonts across devices
    Delta = ((100%x + 100%y) / (320dip + 430dip) - 1)
    Rate = 0.5 'value between 0 to 1.
    Scale = 1 + Rate * Delta
 

geoffschultz

Member
Licensed User
Longtime User
I am trying to create 3 tabs each of which is 1/3rd the width of the tabhost view. I get the width of the tabhost view and divide it by 3 and use that to set the width of the tabwidget. The result is a tab which is probably 1/10 the size of view. In this case the tabhost is 1600 pixels wide, so the calculated width is 533. It doesn't matter whether I do this before or after I add the tabs. What am I doing wrong?

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim tabManager As TabHostExtras
       Activity.LoadLayout("Main")        
  
    If FirstTime Then
        Dim width As Int
        width = tbhPages.Width/3
        Log ("width = " & width)
      
        Dim tw As TabWidget
        tw = tabManager.GetTagWidget(tbhPages)
        tw.width = width      
  
        tbhPages.AddTab("Volunteer","home")      
        tbhPages.AddTab("Customers","customers")  
        tbhPages.AddTab("Donors","donors")
 
Last edited:

stu14t

Active Member
Licensed User
Longtime User
I hope I'm reading this correctly. There is no need to do this. The tabhost will automatically resize your tabs to 1/3 the width
 

geoffschultz

Member
Licensed User
Longtime User
This is most likely due to some scaling issue that I'm having. On some devices I was only seeing 2 of the 3 tabs. I will say that I'm still confused as to what the units are when setting the width.
 

andrewj

Active Member
Licensed User
Longtime User
Hi Martin,
Hopefully this has an easy fix. I use TabHostExtras to completely hide the tab controls, as I control my tabs in code and with an external "tab strip" I have developed.
The following code has worked well with Android versions prior to KitKat:
B4X:
    moTabHostExtras.setTabHostPadding(tabTabs, -5dip, -4dip, -5dip, -4dip)
    moTabHostExtras.setTabHeight(tabTabs, 0)
    moTabHostExtras.setTabVisibility(tabTabs, False)

The trouble is that this doesn't work in KitKat, as I see a blank panel where the tabs would be.
Any ideas?
Thanks
Andrew
 

warwound

Expert
Licensed User
Longtime User
I see no reason why this shouldn't work in Kitkat.
Can you try getting the TabHost's TabWidget and setting the TabWidget's Visivle proeprty to False?

B4X:
Dim TabWidget1 As TabWidget
TabWidget1=TabHostExtras1.GetTabWidget(MyTabHost)
TabWidget1.Visible=False
 

andrewj

Active Member
Licensed User
Longtime User
Hi Martin,
That worked, but there's one wrinkle... You've named the method GetTagWidget(MyTabHost)! Oops.
Thanks anyway
Andrew
 

andrewj

Active Member
Licensed User
Longtime User
I suggest you fix it, but have an undocumented shell method with the old name which maps to it. Nasty, but nicer than the alternatives!
Thanks
Andrew
 

Jerez

Active Member
Licensed User
Longtime User
Hi:

This code does not work for me. I have an Android kitkat:

B4X:
TabHost.setTabHostPadding(TabHost1,0,0,0,0)
    TabHost.setTabContentViewPadding(TabHost1,0,0,0,0)
    TabHost.setTabVisibility(TabHost1, False)


1) In the image 1 i load a view programatically using 100%y and 100%x. that work OK!

2) The image 2 show a layout with a panel inside tinted red and loaded in a TabHost to see the borders....with:
B4X:
TabHost1.AddTabWithIcon2("Locations", LoadBitmap(File.DirAssets, "state1.png"), LoadBitmap(File.DirAssets, "state2.png"), vp.AsView)

but does not fit the screen.


3) The image 3 show the layout in design time using ANCHOR = BOTH but does not work

How can i fixit?

Looks like this guy has same problem:
https://www.b4x.com/android/forum/threads/tabhost-and-the-panels-added-to-it.24992/#post-145014
 

Attachments

  • 01.png
    114.5 KB · Views: 401
  • 02.png
    21.4 KB · Views: 407
  • 03.PNG
    8.9 KB · Views: 399
Last edited:

Prosg

Active Member
Licensed User
Longtime User


i want to change the color of this (in yellow) .... how can i do this pls ?

regards
 

Technofresh

New Member
Licensed User
Where can i download the latest version of TabHostExtras? i tried downloading the link in the first post and it doesn't look like all the features are there that are mentioned.
There is only about 3 functions in the module. Thank You
 

sultan87

Active Member
Licensed User
Longtime User
Bonsoir
je voulais utiliser TabHostExtras
j'ai fait quelques essais qui me semblait être très bon
une fausse manip m'a fait perdre mon projet
j'ai voulu le reconstitué en reprenant l'exemple et je me retrouve avec ceci où je n'ai pas l'icon sur TAB#0
pouvez vous m'aider
il doit y avoir un problème de librairie
Pierre
 

Attachments

  • 2023_01_30_23.54.04.jpg
    129.1 KB · Views: 140

Alexander Stolte

Expert
Licensed User
Longtime User
Every time you write something in the English part in the forum, it's French.... This is the English part of the forum, please write English.

If you want to write french, then you can do it here:
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…