我想要有圆角边缘和特定背景颜色的标签。
请查看我的代码。有了这个,我得到的标签,正确的形状和颜色,但没有文字指标来的标签。请帮忙解决这个
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>
这是一个简单的错误,我不得不改变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在旧API's