B4A Library TabHostExtras

latcc

Banned
When I use your tab library I get the attached image.

But the spaces between each tab are lost. The only way to differentiate between tabs is to curve the tabs' upper corners. Your library merges all the tabs together. Any way to keep them looking separate as with the normal tab display?
 

Attachments

  • tabspacing.jpg
    4.3 KB · Views: 410

neelmon

Member
Licensed User
Longtime User
Selected Tab Back Color

Hi There,

Is it possible to change the Selected Tab Background Color only? Is so, then how?

Regards,
KS
 

warwound

Expert
Licensed User
Longtime User
Hi all.

Yes i'm still around!

B4A is a hobby for me and i have no time for it when i have work to do so my apologies there.

Anyway the big hurdle here is that TabHostExtras is not a simple wrapper type of library...

The library's original few methods all worked fine, but as i added more methods i ran into a problem.
The default B4A TabHost is created and passed to a method - it is an object that has been constructed.

The last few feature requests are actions that need to be performed in the TabHost constructor.
Trying to change the default TabHost's properties and behaviour after it has been constructed is problematic.
The changes are not properly applied - look at this post, see how the modified TabHost is not properly rendered?

The TabIndicators have no space between them and the TabStrip does not properly re-render itself when a Tab is hidden.

Setting the TextSize of a TabIndicator may be possible as requested here.

But i suspect that setting the selected TabIndicator background color would be a problem.

Anyway my point is i don't have the time to investigate what can and what can't be done.

I'd be happy to export the Eclipse project and attach it to this thread if anyone else is interested in updating it - is anyone interested?

Martin.
 

Ricky D

Well-Known Member
Licensed User
Longtime User
I can't get it to work

I have downloaded the the code and the sample project works.

But when I try to put it into my app the TabHostExtras isn't coming up in the ide.

I have a reference to the library v1.5

What am I missing?

regards, Ricky

Disregard - I managed to get it working
 
Last edited:

warwound

Expert
Licensed User
Longtime User
OK here's the exported Eclipse project.

If you look at the .classpath file you'll see that i've got three external archives added to the build path:

B4X:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
   <classpathentry kind="src" path="src"/>
   <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
   <classpathentry kind="lib" path="C:/Program Files (x86)/Android/android-sdk/platforms/android-8/android.jar"/>
   <classpathentry kind="lib" path="C:/Program Files (x86)/Anywhere Software/Basic4android/Libraries/B4AShared.jar"/>
   <classpathentry kind="lib" path="C:/Program Files (x86)/Anywhere Software/Basic4android/Libraries/Core.jar"/>
   <classpathentry kind="output" path="bin"/>
</classpath>

If those libraries are in different locations on your computer then (once you have imported the project into eclipse), right click the project title select Build Path then Configure BuildPath to set the correct paths.

In the src folder you'll see the source code for the current version 1.5 of TabHostExtras and also TabHostExtrasTemp.java 1.51 which would have been the next update.

It contains just two new untested methods:

setTabStripDrawable(TabHost, ColorDrawable, Drawable)

setTabStripEnabled(TabHost, boolean)

These new methods as i mentioned in my last post are problematic...

The B4A TabHost has been created and initialised, it is passed to a TabHostExtras (static) method where we attempt to modify it.
Some methods work as desired and others have unpredictable consequences.

Be sure to keep this thread updated with your progress!

Martin.
 
Last edited:

touchvip

Member
Licensed User
Longtime User
TabHostExtras Compile Error

TabHostExtras Compile Error,Show Error description: Unknown type: reflector

Line 10: Dim Reflector1 As Reflector
 

warwound

Expert
Licensed User
Longtime User
I think you've downloaded the old Code module and not the new library.

This project started off as a Code module and then i made it into a library.
The first post in this thread contains links to both the Code module and the latest version of the library.

You want TabHostExtras_v1.5.zip and NOT TabHostExtrasCodeModule.zip.

Martin.
 

warwound

Expert
Licensed User
Longtime User
TabHostExtrasCodeModule run is just a black screen

I've download and run the TabHostExtrasCodeModule.zip and it work ok here on a 480x800 Froyo emulator.

Screenshot attached.

What device or emulator are you trying to run it on?

Also - is there a reason you are trying to use the code module and not the library?
The code module has very few features compared to the library.
The only reason you might want to use the code module is if you're trying to implement features that are not part of the library.

Martin.
 

Attachments

  • tabhostextrascodemodule.jpg
    10.7 KB · Views: 476

warwound

Expert
Licensed User
Longtime User
I have updated TabHostExtras to version 1.6.

Just one new method to document:

setTabTitle (tabHost1 As TabHost, Title As String, TabIndex As Int)

Set the text of the tab indexed by TabIndex to the String Title.

This code will update the text of the currently selected tab:
B4X:
MyTabHostExtras.setTabTitle(MyTabHost, "A new title", TabHost1.CurrentTab)

The code for this new method gets access to the TextView that displays the TabIndicator title text.
So i imagine that updating the style of that TextView should be possible now - setting FontSize and Color for example.
I'll look at that another day though, i'm too busy to look at it today.

I've added the new version to the first post in this thread.

Martin.
 

warwound

Expert
Licensed User
Longtime User
TabHostExtras updated to version 1.7

I have added two new methods to get and set the size of the tab indicator text:

getTabTextSize (tabHost1 As TabHost) As Float

Get the text size (in pixels) of the TabIndicator text.

setTabTextSize (tabHost1 As TabHost, TextSize As Float)

Set the text size of the TabIndicator text
TextSize is assumed to be in units of dip.

Example code:

B4X:
Log("The current TabIndicator TextSize is: "&MyTabHostExtras.getTabTextSize(TabHost1)&" pixels")   '   returns 14 on Froyo 2.2 emulator
   
'   set the TabIndicator TextSize to 20dip
MyTabHostExtras.setTabTextSize(TabHost1, 20)
   
Log("The new TabIndicator TextSize is: "&MyTabHostExtras.getTabTextSize(TabHost1)&" pixels")   '   return value depends on device density

I was hoping to add methods to set the text color, but as it would have involved wrapping the Android ColorStateList Class it would take more time than i have to spare at the moment.
Maybe another day i'll look at that..

Anyway TabHostExtras version 1.7 is attached to the first post in this thread.

Martin.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Hi Martin,

A couple of questions:

1/ Regarding the adding to setting the TabIndicator TextColor (I thnk thats what the individual tabs are called?). Can you give me a pointer where I can find the TextColor property (I mean in terms of where that object exists). And I will try to add a method to change it.

2/ Is it possible to get the width of a Tab? I tried the following (similar to height) but it didnt seem to work properly.
B4X:
@ShortName("TabWidth")
   public static int getTabWidth(TabHost tabHost1)
     {
       return tabHost1.getTabWidget().getChildAt(0).getLayoutParams().width;
     }

3/ I have added a method for setting the statelistdrawable. It seems to work fine, but it requires that I know the width/height of a tab to work.
B4X:
   @ShortName("setTabSLD") 
   public static void setTabSLD(TabHost tabHost1, StateListDrawable sld)
     {
       TabWidget tabWidget1 = tabHost1.getTabWidget();
       int tabCount = tabWidget1.getChildCount();
       while (tabCount-- > 0)
         tabWidget1.getChildAt(tabCount).setBackgroundDrawable(sld);
     }

And thank you for the library and source code.
 

warwound

Expert
Licensed User
Longtime User
Hi.

This method should help you:

B4X:
/**
 * Set the text size of all TabIndicators
 *TextSize is assumed to be in units of dip.
 */
public void setTabTextSize(TabHost tabHost1, float TextSize){
   TabWidget tabWidget1 = tabHost1.getTabWidget();
   int tabCount = tabWidget1.getChildCount();
   while (tabCount-- > 0) {
      RelativeLayout rLayout = (RelativeLayout) tabWidget1.getChildAt(tabCount);
      ((TextView) rLayout.getChildAt(1)).setTextSize(TextSize);
   }
}


rLayout.getChildAt(0) is the TabIndicator ImageView.

and

rLayout.getChildAt(1) is the TabIndicator TextView.

You may need to look at the documentation for RelativeLayout but i suspect the ImageView and/or TextView will give you the values you want.

Martin.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…