android中实现tab标签切换时的一些效果
16lz
2021-01-23
在android中,如果要做到在TAB切换时,如果要做到TAB的页的背景切换,还是很简单的,
首先要准备2张图片,代码如下:
private void initTabs() {
final TabHost tabs = getTabHost();
final TabWidget tabWidget = tabs.getTabWidget();
for (int i = 0; i < tabWidget.getChildCount(); i++) {
View vvv = tabWidget.getChildAt(i);
//当点到某个标签时,用hit_color的TAB背景色
if (tabs.getCurrentTab() == i) {
vvv.setBackgroundColor(R.color.hit_color);
} else {
vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.leaves4));
}
}
/**
* 当点击tab选项卡的时候,更改当前的背景
*/
tabs.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
for (int i = 0; i < tabWidget.getChildCount(); i++) {
View vvv = tabWidget.getChildAt(i);
if (tabs.getCurrentTab() == i) {
vvv.setBackgroundColor(R.color.hit_color);
} else {
vvv.setBackgroundDrawable(getResources().getDrawable(
R.drawable.leaves4));
}
}
}
});
}
首先要准备2张图片,代码如下:
private void initTabs() {
final TabHost tabs = getTabHost();
final TabWidget tabWidget = tabs.getTabWidget();
for (int i = 0; i < tabWidget.getChildCount(); i++) {
View vvv = tabWidget.getChildAt(i);
//当点到某个标签时,用hit_color的TAB背景色
if (tabs.getCurrentTab() == i) {
vvv.setBackgroundColor(R.color.hit_color);
} else {
vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.leaves4));
}
}
/**
* 当点击tab选项卡的时候,更改当前的背景
*/
tabs.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
for (int i = 0; i < tabWidget.getChildCount(); i++) {
View vvv = tabWidget.getChildAt(i);
if (tabs.getCurrentTab() == i) {
vvv.setBackgroundColor(R.color.hit_color);
} else {
vvv.setBackgroundDrawable(getResources().getDrawable(
R.drawable.leaves4));
}
}
}
});
}
更多相关文章
- Android 5.0 Material 自定义Dialog 背景 字体大小颜色 ui组件颜
- Android Tv 背景动态改变,带过渡效果
- android设置Activity背景色为透明的3种方
- Android 样式系统 | 主题背景和样式
- android中shape绘制背景图片
- Android UI 优化 使用和 标签