How can I remove the space between tab widget?

2020-02-13 01:51发布

I would like to remove the spacing between tabwidgets. By default there is around 1px spacings between tabs. I know some apps like foursquare or posterous are able to remove it. How is the code to do this would look like? I am using 2.3 API.

Thank you for your help

5条回答
The star\"
2楼-- · 2020-02-13 02:07

TabWidget android:showDividers="none"

查看更多
祖国的老花朵
3楼-- · 2020-02-13 02:21

I solve this same problem with this line of code:

 tabHost.getTabWidget().setDividerDrawable(null);
查看更多
等我变得足够好
4楼-- · 2020-02-13 02:26

You can use getTabHost().getTabWidget().setDividerDrawable(R.drawable.empty_divider) method, where R.drawable.empty_divider simple shape with 0px size, such as

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >
    <size
        android:width="0px"
        android:color="@android:color/black"
        android:dashWidth="0px"
        android:dashGap="0px" />
</shape>
查看更多
贪生不怕死
5楼-- · 2020-02-13 02:26

If your build target is Honeycomb onwards, you may use the following code.

if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.HONEYCOMB) {
    tabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
}
查看更多
你好瞎i
6楼-- · 2020-02-13 02:32

You can add android:showDividers="none" to Layout XML

<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:showDividers="none" />
查看更多
登录 后发表回答