Android Question Change a selected tab background in TabHost or TabStrip

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.
I need to change a selected tab background in either TabHost or TabStrip.
I tried to run the example for TabHost with android:targetSdkVersion=26 and it worked fine by itself but with android:targetSdkVersion=30 it's no longer worked.

In TabStrip I don't see any option to do so.

That's what I need (see the attached image)
 

Attachments

  • tabs.jpg
    85.8 KB · Views: 260

PaulMeuris

Well-Known Member
Licensed User
Alex,
You might want to use a TabHost View.
For each tab in the tabhost you have to create a layout file in the designer (Su_layout, Mo_layout, ...).
And in the code you initialize the tabs like so:
TabHost:
    TabHost1.AddTab("S","Su_layout")
    TabHost1.AddTab("M","Mo_layout")
    TabHost1.AddTab("T","Tu_layout")
    TabHost1.AddTab("W","We_layout")
    TabHost1.AddTab("T","Th_layout")
    TabHost1.AddTab("F","Fr_layout")
    TabHost1.AddTab("S","Sa_layout")
In the designer you can specify a color for the layout.
You can add a tab with icons for the selected and not selected state of the tab.


Hope this works for you.
Greetings
Paul
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Thank you for your reply. It works exactly as in your code. The problem is that I need to highlite (change a color) of the selected day of week which is not possible in TabHost now.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Can you show some examples?
You are member here as long as i am and you need a description on how to add a panel to a layout, set a TAG to this panel and get the panel with
tabhost.GetAllViewsRecursive?

It´s really time you learn this language ;-)
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
If you mean TabstrioViewPager, it can be done. If you are still in pursuit of TabstrioViewPager, come back for some help.
View attachment 130228
Thanks, I tried this control and extended it - added icons for each day of week. What I'd like to have is specify x and y for each icon and add a devider between icons
 

Attachments

  • Screenshot_20220612-175156.png
    114.5 KB · Views: 195
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…