Effect picture:
font selection and color change and navigation picture replacement effect
Add reference:
1. In the project's build.gradle, add the following code:
implementation 'com.ycl.tabview.library:tabviewlibrary:1.0'
2. After updating the project, add the following code to the layout:
<com.ycl.tabview.library.TabView
android:id="@+id/tabView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.ycl.tabview.library.TabView>
As shown in the figure:
3. Add code in the class to add data to the navigation bar:
List<TabViewChild> tabViewChildList=new ArrayList<>();
TabViewChild tabViewChild00=new TabViewChild(R.drawable.ic_star_04,R.drawable.ic_satr_01,"假面", new NewsFragment());
TabViewChild tabViewChild01=new TabViewChild(R.drawable.ic_star_04,R.drawable.ic_satr_01,"消息", new NewsFragment());
TabViewChild tabViewChild02=new TabViewChild(R.drawable.ic_star_04,R.drawable.ic_satr_01,"广场", new SquareFragment());
TabViewChild tabViewChild03=new TabViewChild(R.drawable.ic_star_04,R.drawable.ic_satr_01,"我的", new UserFragment());
tabViewChildList.add(tabViewChild00);
tabViewChildList.add(tabViewChild01);
tabViewChildList.add(tabViewChild02);
tabViewChildList.add(tabViewChild03);
The first parameter: when a tab on the navigation bar is clicked, the corresponding switched picture. The
second parameter: when the tab on the navigation bar is not clicked, the corresponding switched picture. The
third parameter: on the navigation bar. The text display of a tab of the
fourth parameter: the Fragment object corresponding to a tab on the navigation bar, which can be passed in
4. Set the data source
//这里是添加数据源 tabView是获取到的标签
TabView tabView = findViewById(R.id.tabView);
tabView.setTabViewChild(tabViewChildList,getSupportFragmentManager());
//下面的是样式定义 可以不添加
tabView.setTextViewSelectedColor(Color.BLUE);
tabView.setTextViewUnSelectedColor(Color.BLACK);
tabView.setTabViewHeight(dip2px(52));
tabView.setImageViewTextViewMargin(2);
tabView.setTextViewSize(14);
tabView.setImageViewWidth(dip2px(30));
tabView.setImageViewHeight(dip2px(30));
tabView.setTabViewGravity(Gravity.TOP);
tabView.setTabViewDefaultPosition(2);
The above can be used to achieve the previous effect. You
can't relax and stop learning.