我需要为选项卡创建一个特定的形状。它应该是这样的
是否可以通过形状创建它?或者只是将其用作图像?
我还看到有些人在必须创建非常专业的选项卡时使用这种方式:他们只是在 photoshop 中创建所有选项卡的所有变体,选择的和未选择的,(例如,tab1_selected,tab1_unselected,...),但是他们不会为每个选项卡创建图像,而是文学性地创建整个 TabWidget 图像(例如,选中 tab1 的图像,而其他选项卡未选中),然后在选择某个选项卡时加载适当的图像。
- 这样做正确吗?通过这种方式,您可以创建带有厚底部分隔线等的非常酷的标签。
- 我应该如何以这种方式加载整个 TabWidget 背景?通过
background
属性或其他方式的通常方式?
使用下面的代码,代码中的MyClass
就是写代码的ClassName:
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
MyClass.setTabColor(tabHost);
}
});
public static void setTabColor(TabHost tabhost) {
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) {
tabhost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_bg); //unselected
}
tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundResource(R.drawable.tab_bg_selected); // selected
}
我是一名优秀的程序员,十分优秀!