zoukankan      html  css  js  c++  java
  • 设置TabWidget的样式的方法、关联Fragment与tabwidget的方法、点击tab显示相应Fragment方法

    private void updateTabHost(TabHost tabHost) {
            int count = tabHost.getTabWidget().getChildCount();
            for (int i = 0; i < count; i++) {
                View view = tabHost.getTabWidget().getChildTabViewAt(i);
                int tabHeightPx = DisplayUtil.dp2px(this, 80 // tab高度,此处单位为dp,经过DisplayUtil后转为px然后赋值
                        );
                view.getLayoutParams().height = tabHeightPx; // tabWidget.getChildAt(i)
                final TextView tv = (TextView) view
                        .findViewById(android.R.id.title);
                tv.setTextSize(28);
                tv.setTextColor(this.getResources().getColorStateList(
                        android.R.color.white));
            }
        }

    这是更改其tabwidget样式的方法

    private void changeLayout() {
            // 根据用户的点击位置的下标显示相应的fragment
            tabHost.setCurrentTab(currentlayout);
        }
    
        private void setFragment() {
            // 通过组件的id初始化tabHost的实例
            tabHost = (TabHost) findViewById(R.id.tabhost);
            tabHost.setup();
            // tabWidget = tabHost.getTabWidget();
            // 往tabHost分别添加fragment
            tabHost.addTab(tabHost
                    .newTabSpec("main_social")
                    .setIndicator(
                            "动态",
                            this.getResources().getDrawable(
                                    R.drawable.checkbox_full_pressed))
                    .setContent(R.id.frag_social));
            tabHost.addTab(tabHost
                    .newTabSpec("main_geomark")
                    .setIndicator(
                            "联系人",
                            this.getResources().getDrawable(
                                    R.drawable.checkbox_full_pressed))
                    .setContent(R.id.frag_geomark));
            tabHost.addTab(tabHost
                    .newTabSpec("main_timeaxis")
                    .setIndicator(
                            "动态",
                            this.getResources().getDrawable(
                                    R.drawable.checkbox_full_pressed))
                    .setContent(R.id.frag_timeaxis));
    
            tabHost.addTab(tabHost
                    .newTabSpec("main_travel")
                    .setIndicator(
                            "设置",
                            this.getResources().getDrawable(
                                    R.drawable.checkbox_full_pressed))
                    .setContent(R.id.frag_travel));
    
            tabHost.addTab(tabHost
                    .newTabSpec("main_activity")
                    .setIndicator(
                            "设置",
                            this.getResources().getDrawable(
                                    R.drawable.checkbox_full_pressed))
                    .setContent(R.id.frag_activity));
    
            updateTabHost(tabHost);//更新布局样式等
            
            tabHost.setCurrentTab(0);// 设置默认显示布局
        }

    这是关联Fragment和tabWidget点击的方法,此方法放在onCreate方法内~

  • 相关阅读:
    《GDB常用基本》
    《Linux守护进程》
    <C语言知识点 —— 数组赋值字符串>
    《Linux知识点》
    玩转----select模块操作下拉框-selenium
    玩转----selenium--下拉框select
    玩转----selenium-滚动条的几种方式
    玩转----python-装饰器
    玩转----解决selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid 'expiry'
    玩转----iframe框架怎样来定位,并说明iframe框架中不变和可变的属性分别是什么?多个iframe框架怎么处理?iframe和frame区别:
  • 原文地址:https://www.cnblogs.com/huangsheng/p/3346326.html
Copyright © 2011-2022 走看看