In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.