Custom tabs in Android
I am trying to change the content of the tab header but am struggling. I can see that it is possible to pass a View to the setIndicator() method. I tried this and got a removeParent() warning which I dont understand. Has a开发者_如何学Gonyone managed to do this successfully. If so can you explain how you did it please?
Clive
This problem occurs when you use the same view in different tabs. You must use a different view. This is what I did:
view.setImageResource(R.drawable.videotab);
view1.setImageResource(R.drawable.musictab);
intent = new Intent().setClass(this, CustomList.class);
spec = tabHost.newTabSpec("Video").setIndicator(view)
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, CustomListOne.class);
spec = tabHost.newTabSpec("Music").setIndicator(view1)
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
You don't have to use different View
s. You can simply inflate the same layout again when you need it. That means you inflate your layout, set everything you need on your different View
s and then you set it as your indicator. If you need another tab just do it again.
精彩评论