在Android中使用Intent自定义TabView

nodio 发布于 2019-03-15 android 最后更新 2019-03-15 14:08 1 浏览

我想在Image中像下面一样创建Tabview。我尝试过,但无法得到正确的看法。

Custom Tab 这是我的代码..它没有给我确切的看法,我想要的。那么,我该如何定制它。
public class BandInfo extends TabActivity implements OnTabChangeListener {
TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.band_info);
tabHost = getTabHost();
tabHost.getTabWidget().setBackgroundResource(R.drawable.footerbar);
// Tab for Bio
    TabSpec bioSpec = tabHost.newTabSpec("Bio");
    // Setting Title for Tab
    bioSpec.setIndicator("Bio");
    Intent bioIntent = new Intent(this,Bio.class);
    bioSpec.setContent(bioIntent);
// Tab for Upcoing Shows
    TabSpec upcomingShowSpec = tabHost.newTabSpec("Upcoming Shows");
    upcomingShowSpec.setIndicator("Upcoming Shows");
    Intent upcomingShowIntent = new Intent(this, UpcomingShow.class);
    upcomingShowSpec.setContent(upcomingShowIntent);
// Tab for Band Members
    TabSpec bandMemberSpec = tabHost.newTabSpec("Band Members");
    bandMemberSpec.setIndicator("Band Members");
    Intent bandMemberIntent = new Intent(this, BandMembers.class);
    bandMemberSpec.setContent(bandMemberIntent);
// Adding all TabSpec to TabHost
    tabHost.addTab(bioSpec); // Adding Bio Tab
    tabHost.addTab(upcomingShowSpec); // Adding Upcoming Show Tab
    tabHost.addTab(bandMemberSpec); // Adding Band Members Tab
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
    {
        tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.footerbar);
    }
    tabHost.getTabWidget().setDividerDrawable(R.drawable.footer_saprater);
}
@Override
public void onTabChanged(String tabId) {
    // TODO Auto-generated method stub
    for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
    {
        tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.footerbar);
    }
    tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(R.drawable.bandmember_active);
}
请帮助我一些代码... 提前致谢.. Output Screen 这是我得到的输出屏幕。
已邀请:

kodit

赞同来自:

嘿,我发现了这个。尝试这个。你一定会成功的。 http://code.google.com/p/android-custom-tabs/ 设置宽度, tabHost.getTabWidget().getChildAt(0).getLayoutParams().width =(int) 30; 另请查看此链接:http://adanware.blogspot.in/2012/04/android-custom-tab-layouts-just-using.htmlhttp://www.speakingcode.com/2011/12/01/creating-custom-views-for-tabs-in-an-android-activity-using-tabhost-and-tabwidget/