gpt4 book ai didi

android - 如何为 TabHost 制作异形?

转载 作者:太空宇宙 更新时间:2023-11-03 13:36:35 26 4
gpt4 key购买 nike

我需要为选项卡创建一个特定的形状。它应该是这样的

enter image description here

是否可以通过形状创建它?或者只是将其用作图像?

我还看到有些人在必须创建非常专业的选项卡时使用这种方式:他们只是在 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
}

关于android - 如何为 TabHost 制作异形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6455864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com