2010-07-17 63 views
1

任何人都可以使用android 2.1 +帮助我实现TabWidget的圆角。我基本上试图纯粹通过xml配置给TabWidget一个自定义主题。我尝试了以下,但只有文字颜色改变。如何在Android 2.1中实现圆形标签+

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="Tab_ForeColor">#6095C1</color> 
    <color name="Tab_BackgroundColor">#411485</color> 

    <style name="TestTheme" parent="android:Theme.Black"> 
     <item name="android:tabWidgetStyle">@style/TestTab</item> 
    </style> 

    <style name="TestTab" parent="@android:style/Widget.TabWidget"> 
     <item name="android:textAppearance">@style/TestTextApperance</item> 
     <item name="android:drawable"> 
      <drawable name="rounded_tab"> 
       <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle"> 
        <stroke android:width="3dip" android:color="@android:color/white" /> 
        <solid android:color="@android:color/white" /> 
        <corners android:bottomRightRadius="0.1dip" 
         android:bottomLeftRadius="0.1dip" android:topLeftRadius="15dip" 
         android:topRightRadius="15dip" /> 
       </shape> 
      </drawable> 
     </item> 
    </style> 

    <style name="TestTextApperance"> 
     <item name="android:textSize">14dp</item> 
     <item name="android:textStyle">normal</item> 
     <item name="android:textColor">@color/Tab_ForeColor</item> 
    </style> 
</resources> 

TIA

安德鲁

回答

4

一个解决方案是用设置在标签圆角的图像,我知道的,俗气的解决方案,但工作。

tab = tabs.newTabSpec("tab_Busquedas"); 
tab.setContent(new Intent().setClassName("com.grapp", "com.grapp.homes").putExtras(bundle)); 
tab.setIndicator(null,null); 
tabs.addTab(tab); 
//here you set the image with rounded corners over the tab. 
tabs.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.mytab_roundedcorners); 

R.drawable.mytab_roundedcorners将成为选择器。

+0

感谢您的回答。如果可能的话,我将继续尝试寻找一种纯粹用xml实现的方法,但我会接受你的答案,因为它确实按我的要求做了。 :-) 谢谢。 – 2010-07-19 07:37:49