Android 中TabLayout实现Tab自定义和选中文字加粗
来源:互联网 发布:托勒密王朝 知乎 编辑:程序博客网 时间:2024/06/06 05:43
在Android开发当中,我们几乎都得用到TabLayout+Fragment来实现信息的展示,但是,很多时候我们的需要又很不同,
TabLayout的基本使用推荐以下文章:http://www.jianshu.com/p/2b2bb6be83a8
需求一:自定义TabLayout中Tab的布局
这里我们使用到是不同与TabLayout的默认布局,这样的话,需要什么样的样式都可以自己实现。
1.实现这样的效果主要是在添加Tab时,我们使用自定义的布局
private void addCustomTab(List<GetIconBean.IconListBean.CategoryBean> listData, int i) { TabLayout.Tab tab = tabLayout.newTab(); //加载自定义的布局 View view = LayoutInflater.from(context).inflate(R.layout.widget_choose_icon_tab_bg, null); TextView tv = (TextView) view.findViewById(R.id.choose_icon_tab_tv); tv.setText(listData.get(i).getName()); tab.setCustomView(view); tabLayout.addTab(tab); }
- widget_choose_icon_tab_bg.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/choose_icon_tab_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="2dp" android:background="@drawable/selector_icon_choose_txt_bg" /></LinearLayout>
selector_icon_choose_txt_bg.xml
文字选中与未选中的selector
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/shape_icon_choose_select" android:state_checked="true" /> <item android:drawable="@drawable/shape_icon_choose_select" android:state_selected="true" /> <item android:drawable="@drawable/shape_icon_choose_no_select" /></selector>
- shape_icon_choose_select.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/line_gray"/> <stroke android:color="@color/tv_black" android:width="1dp"/></shape>
- shape_icon_choose_select.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:color="@color/tv_black" android:width="1dp"/></shape>
当然也可以自己实现任何布局,例如文字左边添加图片……
需求二:TabLayout选中文字加粗
这里实际上是有一个库,对TabLayout进行了封装,使用和TabLayout几乎相同,使用很简单
文章地址:http://blog.csdn.net/a1533588867/article/details/53810409
github:https://github.com/AndroidKun/XTabLayout
阅读全文
0 0
- Android 中TabLayout实现Tab自定义和选中文字加粗
- Android---Tablayout自定义tab
- js实现textarea选中文字并加粗
- 设置tablayout选中文字颜色和背景图片
- TabLayout和ViewPager搭配使用中如何设置Tab背景颜色(无须自定义TabLayout)
- Android Tablayout 自定义Tab布局的使用
- 怎么给TabLayout的文字加粗变色
- 实现文字部分加粗
- android TextView文字加粗
- Android TabLayout、ViewPager实现顶部和底部Tab导航 点击滑动切换Tab页面
- 【TabLayout】 Android 另一种Tab的实现
- TabLayout android Tab的一种实现方式
- Android TabLayout与ViewPager实现动态Tab
- 【Android】另一种Tab的实现--TabLayout
- 自定义TabLayout的Tab
- Android tablayout 单纯更改Tab的文字颜色
- Android中自定义Tab的实现
- Android中自定义tabhost的TAB页面被选中时TAB底部的颜色
- PHP面向对象
- 第一次
- linux下elasticsearch
- ViewPager限定预加载的页面个数setOffscreenPageLimit(int limit)
- 内存页面调度、页面交换
- Android 中TabLayout实现Tab自定义和选中文字加粗
- 单机服务器支持千万级并发长连接的压力测试
- 公有云、私有云、混合云之间的区别,你知道吗?
- Android ListView 常见问题记录
- 完全卸载oracle11g步骤
- python中的多线程与多进程
- 视频编解码,FFMPEG,RTP问题汇总
- [linux学习笔记]之一:ubuntu ch340调试备忘
- NSAttributedString文本属性设置的使用