Android自定义FragmentTabhost之ZzFragmentTabhost

Github传送门:ZzFragmentTabhost

最新觉得安卓自带的FragmentTabhost的适配性不佳且用起来比较麻烦。
于是自己撸了个,分享给大家,欢迎批评指正。

ZzFragmentTabHost

A powerful FragmentTabhost.

Gradle

compile 'me.zhouzhuo.zzfragmenttabhost:zz-fragment-tabhost:1.0.1'

Maven

<dependency>
  <groupId>me.zhouzhuo.zzfragmenttabhost</groupId>
  <artifactId>zz-fragment-tabhost</artifactId>
  <version>1.0.1</version>
  <type>pom</type>
</dependency>

这里写图片描述

用法简介

res/layout:


    <me.zhouzhuo.zzfragmenttabhost.ZzFragmentTabHost
        android:id="@+id/zft"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

    </me.zhouzhuo.zzfragmenttabhost.ZzFragmentTabHost>

java:


        ZzFragmentTabHost zft = (ZzFragmentTabHost) findViewById(R.id.zft);

        zft.setUp(this, getSupportFragmentManager(), R.id.fgm_container) //设置fragment的容器FrameLayout的id
                .initTabsWithCount(4) //设置Fragment的数量
                .setFragmentClazz(      //设置Fragment的class
                        FragmentOne.class,
                        FragmentTwo.class,
                        FragmentThree.class,
                        FragmentFour.class)
                .setTabNameWithResId(R.array.tab_names)   //设置Tab文字resid
                .setImagePressIds(                      //设置tab按下时图片id
                        R.drawable.mainicon_checked,
                        R.drawable.mainicon_checked,
                        R.drawable.mainicon_checked,
                        R.drawable.mainicon_checked)
                .setImageNormalIds(                     //设置tab未选择时图片id
                        R.drawable.mainicon_normal,
                        R.drawable.mainicon_normal,
                        R.drawable.mainicon_normal,
                        R.drawable.mainicon_normal)
                .setTabTextSizeNormalAll(DisplayUtil.scaleValue(this, 24))      //设置tab未选择时文字大小
                .setTabTextSizeSelectedAll(DisplayUtil.scaleValue(this, 24))    //设置tab选择时文字大小
                .setTabImgSizeNormalAll(DisplayUtil.scaleValue(this, 50))       //设置tab未按下时图片大小
                .setTabImgSizeSelectedAll(DisplayUtil.scaleValue(this, 50))     //设置tab按下时图片大小
                .setTabTextColorResIdNormalAll(R.color.colorTabGray)            //设置tab未按下时文字颜色
                .setTabTextColorResIdSelectedAll(R.color.colorTabMain)          //设置tab按下时文字颜色
                .setMarkNumberSizeAll(DisplayUtil.scaleValue(this, 20))         //设置tab角标文字大小
                .setMarkWidthAll(DisplayUtil.scaleValue(this, 50))              //设置tab角标宽度
                .setMarkHeightAll(DisplayUtil.scaleValue(this, 40))             //设置tab角标高度
                .setMarkNumberAt(0, 100)                                        //设置第postion位置的tab对应的角标的值
                .showMarkAt(0)                                                  //显示第position位置的tab对应的角标
                .setOnTabClickListener(new ZzFragmentTabHost.OnTabClickListener() {    //tab点击监听
                    @Override
                    public void onTabClick(ZzTab tab, boolean changed, int position) {

                    }
                })
                .setSelection(0);          //默认选中第一个tab
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值