Tab Dividers Not Showing In ICS

前端 未结 3 729
既然无缘
既然无缘 2021-01-06 08:08

I have a problem with .setDividerDrawable() only working in versions lower than Ice Cream Sandwich. When I run the emulator the tabs show perfectly, but no divider. When emu

相关标签:
3条回答
  • 2021-01-06 08:48

    I had the same problem, I finally ended up adding the separators manually. Adding ImageView between the tabs..

    public class MyTabApp extends TabActivity {
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            ImageView divider = new ImageView(this);
            divider.setImageResource(R.drawable.tab_seperator);
    
            TabHost tabHost = getTabHost();
            TabHost.TabSpec spec;
            Intent intent;
    
            intent = new Intent().setClass(this, Page1.class);
            spec = tabHost.newTabSpec("page1").setIndicator(getLayoutInflater().inflate(R.layout.tab1, null))
                      .setContent(intent);
            tabHost.addTab(spec);
    
            tabHost.getTabWidget().addView(divider, LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
    
            intent = new Intent().setClass(this, Page2.class);
            spec = tabHost.newTabSpec("page2").setIndicator(getLayoutInflater().inflate(R.layout.tab2, null))
                      .setContent(intent);
            tabHost.addTab(spec);
        } 
    }
    
    0 讨论(0)
  • 2021-01-06 09:00

    you can try this code!

    if(Build.VERSION.SDK_INT >= 11)
        mTabHost.getTabWidget().setShowDividers(TabWidget.SHOW_DIVIDER_MIDDLE);
    
    0 讨论(0)
  • 2021-01-06 09:03

    This behavior seems to be a default behavior in ICS tab themes and needs a work around. Take a look at this answer, specifically the one given by @Janusz, the OP.

    0 讨论(0)
提交回复
热议问题