Android:tabwidget圆形边缘文本指示器未来

时间:2011-12-21 06:26:38

标签: android rounded-corners tabwidget

我想要带有圆边和特定背景颜色的标签。

请在此处查看我的代码。有了这个,我得到了标签,正确的形状和颜色,但没有文字指示器出现在标签中。请帮助解决这个问题

private void setViewContent() {
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.events_tabs);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);
    tabHost = getTabHost();


     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, EventsListActivity.class);
        intent.putExtra("PASTEVENT", 0);
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("UpcomingEvents").setIndicator("UpcomingEvents").setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this,EventsListActivity.class);
        intent.putExtra("PASTEVENT", 1);
        spec = tabHost.newTabSpec("PastEvents").setIndicator("PastEvents"
                         )
                      .setContent(intent);

        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);

    tabHost.setOnTabChangedListener(this);

    setTabColor(tabHost);

}

public static void setTabColor(TabHost tabhost) {
    for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) {

    //tabhost.getTabWidget().getChildAt(i)
    //          .setBackgroundColor(Color.parseColor("#ff0000")); 

         tabhost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_notpressed_bg);

    }
     tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundResource(R.drawable.tab_pressed_bg);
//  tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab())
    //      .setBackgroundColor(Color.parseColor("#C11B17")); // selected

}



public void onTabChanged(String tabName) {

    setTabColor(tabHost);

}

event_tab.xml:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:paddingTop="10dip" >
<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
    >
    <TabWidget android:id="@android:id/tabs" 
                android:layout_width="wrap_content" android:layout_height="40dip" 
        android:layout_below="@+id/text1view" android:layout_margin="15dip"
        android:layout_centerHorizontal="true"/>            
        <FrameLayout android:id="@android:id/tabcontent" 
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:layout_below="@android:id/tabs"/>



    </RelativeLayout>
</LinearLayout>

tab_pressed_bg.xml

    <?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <gradient android:startColor="#C11B17" android:endColor="#C11B17" 
            android:angle="270"/> 

    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 
</shape> 

tab_not_pressed_bg

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="rectangle"> 
     <gradient android:startColor="#ff0000" android:endColor="#ff0000" 
            android:angle="270"/> 

    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
     android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 

</shape> 

1 个答案:

答案 0 :(得分:0)

这是一个简单的错误,我不得不改变tabwidget的高度!!

<TabWidget android:id="@android:id/tabs" 
                android:layout_width="wrap_content" android:layout_height="40dip" 
        android:layout_below="@+id/text1view" android:layout_margin="15dip"
        android:layout_centerHorizontal="true"/>    

为了让灰色边框受到抑制,我尝试了许多建议,比如玩风格和它们,只有工作才能在链接中给出答案

tabStripEnabled for TabWidget in Older API's