自定义Tab选项卡
来源:互联网 发布:sql yuju data 编辑:程序博客网 时间:2024/05/21 06:25
效果:
代码:
代码:
import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.widget.*;import android.widget.TabHost.OnTabChangeListener;import android.os.Build;import android.view.View;import java.lang.reflect.Field;import android.view.LayoutInflater;public class testTabActivity extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int width =45; int height =48; final TabHost tabs = getTabHost(); final TabWidget tabWidget = tabs.getTabWidget(); Field mBottomLeftStrip; Field mBottomRightStrip; LayoutInflater.from(this).inflate(R.layout.tab_views, tabs.getTabContentView(), true); tabs.addTab(tabs.newTabSpec("first tab") .setIndicator("信息",getResources().getDrawable(R.drawable.m)) .setContent(new Intent(testTabActivity.this,OneActivty.class)) ); tabs.addTab(tabs.newTabSpec("second tab") .setIndicator("收藏",getResources().getDrawable(R.drawable.n)) .setContent(R.id.content)); tabs.addTab(tabs.newTabSpec("second tab") .setIndicator("设置",getResources().getDrawable(R.drawable.s)) .setContent(R.id.content)); for (int i =0; i < tabWidget.getChildCount(); i++) { /** * 设置高度、宽度,不过宽度由于设置为fill_parent,在此对它没效果 */ tabWidget.getChildAt(i).getLayoutParams().height = height; tabWidget.getChildAt(i).getLayoutParams().width = width; /** * 设置tab中标题文字的颜色,不然默认为黑色 */ final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title); tv.setTextColor(this.getResources().getColorStateList(android.R.color.white)); /** * 此方法是为了去掉系统默认的色白的底角 * * 在 TabWidget中mBottomLeftStrip、mBottomRightStrip * 都是私有变量,但是我们可以通过反射来获取 * * 由于还不知道Android 2.2的接口是怎么样的,现在先加个判断好一些 */ if (Float.valueOf(Build.VERSION.RELEASE) <= 2.1) { try { mBottomLeftStrip = tabWidget.getClass().getDeclaredField ("mBottomLeftStrip"); mBottomRightStrip = tabWidget.getClass().getDeclaredField ("mBottomRightStrip"); if(!mBottomLeftStrip.isAccessible()) { mBottomLeftStrip.setAccessible(true); } if(!mBottomRightStrip.isAccessible()){ mBottomRightStrip.setAccessible(true); } mBottomLeftStrip.set(tabWidget, getResources().getDrawable (R.drawable.no)); mBottomRightStrip.set(tabWidget, getResources().getDrawable (R.drawable.no)); } catch (Exception e) { e.printStackTrace(); } } else { /** * 不做任何处理 */ } View vvv = tabWidget.getChildAt(i); if(tabs.getCurrentTab()==i){ vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_button)); } else { vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.bar)); } } /** * 当点击tab选项卡的时候,更改当前的背景 */ tabs.setOnTabChangedListener(new OnTabChangeListener(){ @Override public void onTabChanged(String tabId) { // TODO Auto-generated method stub for (int i =0; i < tabWidget.getChildCount(); i++) { View vvv = tabWidget.getChildAt(i); if(tabs.getCurrentTab()==i){ vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_button)); } else { vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.bar)); } } }}); } }
- 自定义Tab选项卡
- 自定义Tab选项卡
- 自定义Tab选项卡样式
- javascript+div样式的自定义tab选项卡
- 简单选项卡TAB
- 个性TAB选项卡
- html tab选项卡
- Tab选项卡
- css tab选项卡
- tab选项卡
- 删除Tab选项卡
- javascript-tab选项卡
- 触屏tab选项卡
- tab选项卡案例
- tab选项卡
- Tab选项卡切换
- tab选项卡
- Tab选项卡切换
- Android开发之蓝牙(Bluetooth)操作(二)--修改本机蓝牙设备的可见性,并扫描周围可用的蓝牙设备(转)
- Android中的TabHost
- Selenium的RC方式编写的测试脚本部分迁移到WebDriver方式混用的简单示例
- android设置button透明度
- 由浅入深探究mysql索引结构原理、性能分析与优化
- 自定义Tab选项卡
- 理解MySQL——索引与优化
- Android读写文件二
- OXFeeeFeee指针的含义
- centOS怎样强制卸载PHP以及自定义安装PHP
- 字符串连接
- 今天买了两本书
- .net 不让浏览器缓存
- JBOSS AS7 数据源配置一条龙+jersey 发布应用关键点