改变android 选项卡的背景色
16lz
2022-03-31
看如下代码:
mTabHost = (TabHost) findViewById(R.id.tabhost); mTabHost.setup(); final TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs); LayoutInflater inflater_tab1 = LayoutInflater.from(this); inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab1, mTabHost .getTabContentView()); inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab2, mTabHost .getTabContentView()); inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab3, mTabHost .getTabContentView()); // inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab4, mTabHost // .getTabContentView()); // inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab5, mTabHost // .getTabContentView()); // inflater_tab1.inflate(R.layout.mobile_phone_cashier_tab1_request, // mTabHost // .getTabContentView()); mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator( getString(R.string.sy)).setContent(R.id.FrameLayout01)); mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator( getString(R.string.cd)).setContent(R.id.FrameLayout02)); mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator( getString(R.string.jyjl)).setContent(R.id.FrameLayout03)); // mTabHost.addTab(mTabHost.newTabSpec("tab4").setIndicator( // getString(R.string.yye)).setContent(R.id.FrameLayout04)); // mTabHost.addTab(mTabHost.newTabSpec("tab5").setIndicator( // getString(R.string.jyjl)).setContent(R.id.FrameLayout05)); tabWidget.setBackgroundResource(R.drawable.tab_bg); Field mBottomLeftStrip; Field mBottomRightStrip; for (int i = 0; i < tabWidget.getChildCount(); i++) { final TextView tv = (TextView) tabWidget.getChildAt(i) .findViewById(android.R.id.title); tabWidget.getChildAt(i).getLayoutParams().height = 40; if (i == 0) { tabWidget.getChildAt(i).setBackgroundResource( R.drawable.tab_kuang);//设置背景 tv.setTextColor(Color.rgb(202, 151, 0)); } else { tabWidget.getChildAt(i) .setBackgroundResource(R.drawable.tab_bg); tv.setTextColor(Color.WHITE); tabWidget.getChildAt(i).setClickable(false); } tv.setTextSize(15); tv.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM); }
原理就是更改系统自带的tabwidget
更多相关文章
- Android代码实现飞行模式的打开
- android 監聽系統屬性變化的方法
- Android监听WebView滑动到底部
- android开发实战!2021年Android技术下半场在哪?含泪整理面经
- git新建本地仓库关联远程仓库(无需移动本地仓库文件)
- 开源分享!2021年最新 Android(安卓)资料汇总,从小白到大佬的进阶之
- 改变 Android(安卓)EditText 的边框
- Android(安卓)Activity设置全屏
- android 多线程下载原理