Get the App
SLTechnology News&Howtos  ›  Development  › 

How does android TabHost solve the following white line

Shulou Source: shulou.com Published: 2022-06-02 10:23:30 09月15日 Update

Android TabHost how to solve the following white line, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

I used to use GridView and ActivityGroup to do paging. Because I think TabHost is not easy to use, there is also the reason why my level is poor. If you help, rewrite view any problem can be solved, ha ha, the following please see the implementation process, is actually very simple.

Code snippet:

?

01

02

03

04

05

06

07

08

09

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

twenty-three

twenty-four

twenty-five

twenty-six

twenty-seven

twenty-eight

twenty-nine

thirty

thirty-one

thirty-two

thirty-three

thirty-four

thirty-five

thirty-six

thirty-seven

thirty-eight

thirty-nine

forty

forty-one

forty-two

forty-three

forty-four

forty-five

forty-six

forty-seven

forty-eight

forty-nine

fifty

fifty-one

fifty-two

fifty-three

fifty-four

fifty-five

fifty-six

fifty-seven

fifty-eight

fifty-nine

sixty

sixty-one

sixty-two

sixty-three

sixty-four

sixty-five

sixty-six

sixty-seven

sixty-eight

sixty-nine

seventy

seventy-one

seventy-two

seventy-three

seventy-four

seventy-five

seventy-six

seventy-seven

Public class MyActivity extends TabActivity {

Private TabWidget tabWidget

/ * Called when the activity is first created. , /

Public void onCreate (Bundle savedInstanceState) {

Super.onCreate (savedInstanceState)

SetContentView (R.layout.main)

Resources res = getResources (); / / Resource object to get Drawables

Final TabHost tabHost = getTabHost (); / / The activity TabHost

TabHost.TabSpec spec; / / Resusable TabSpec for each tab

Intent intent; / / Reusable Intent for each tab

/ / Create an Intent to launch an Activity for the tab (to be reused)

Intent = new Intent () .setClass (this, ArtistsActivity.class)

/ / Initialize a TabSpec for each tab and add it to the TabHost

Spec = tabHost

.newTabSpec ("artists")

.setIndicator ("Artists"

Res.getDrawable (R.drawable.ic_tab_artists))

.setContent (intent)

TabHost.addTab (spec)

/ / Do the same for the other tabs

Intent = new Intent () .setClass (this, AlbumsActivity.class)

Spec = tabHost

.newTabSpec ("albums")

.setIndicator ("Albums"

Res.getDrawable (R.drawable.ic_tab_artists))

.setContent (intent)

TabHost.addTab (spec)

Intent = new Intent () .setClass (this, SongsActivity.class)

Spec = tabHost

.newTabSpec ("songs")

.setIndicator ("Songs"

Res.getDrawable (R.drawable.ic_tab_artists))

.setContent (intent)

TabHost.addTab (spec)

TabHost.setCurrentTab (2)

View v

TabWidget = tabHost.getTabWidget ()

For (int I = 0; I < tabWidget.getChildCount (); iTunes +) {

/ / get the tabview entry

V = tabWidget.getChildAt (I)

/ / set tab background color

V.setBackgroundResource (android.R.color.white)

/ / get the textview control (default is white)

TextView textView = (TextView) v.findViewById (android.R.id.title)

TextView.setTextColor (Color.BLACK)

/ / default options to deal with

If (tabHost.getCurrentTab () = = I)

V.setBackgroundResource (R.drawable.renren_sdk_pay_repair_btn)

}

/ / tabchanged monitoring

TabHost.setOnTabChangedListener (new OnTabChangeListener () {

/ / tabId displays the value in newTabSpec

@ Override

Public void onTabChanged (String tabId) {

/ / initialize all view backgrounds first.

For (int I = 0; I < tabHost.getTabWidget (). GetChildCount (); iTunes +) {

View v = tabHost.getTabWidget () .getChildAt (I)

/ / set tab background color

V.setBackgroundResource (android.R.color.white)

/ / selected for processing

If (tabHost.getCurrentTab () = = I) {

V.setBackgroundResource (R.drawable.renren_sdk_pay_repair_btn)

}

}

}

});

}

}

In fact, it is the annotated part of those lines, which I believe you will understand at a glance.

Solve the method of white line under Tab:

First we need to get the paging view and textview controls for Tab, because the default font for textview is white. We have to deal with it. Get it and process it accordingly (that is, the background should be added, and the font color should be changed). * We need to OnTabChangedListener the TabHost; it is not listening. Is to use his click to execute the event.

After reading the above, have you mastered how android TabHost solves the white line below? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Background color processing font that is methods problems monitoring content reasons controls more white helpless for this not good that is events code for this Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information Xiaomi Redmi Shulou Technology