Android UI implements the bottom switching label fragment
A UI effect to be shared in this blog is to realize the bottom switching tab. You must have encountered this effect in some applications. The most typical is wechat. You can slide the page left and right, or click the tab to slide the page. How do they realize it? In order to briefly introduce how to click the bottom switching tab.
Let's take a look at the renderings we want to achieve:
The implementation of such a page is actually very simple. First, we start with the layout: it is divided into three parts: Part I: top navigation bar layout Part II: middle display content layout Part III: bottom label layout
/BottomTabDemo/res/layout/activity_ main.xml
The above is the layout code. Here is how to switch the fragment by clicking the label: we will find that the first tab is selected initially, and the color of the picture and font is different from the other two tabs, so what we need to do is to change the status of the label when switching the label, mainly changing two contents:
Then we switch labels to display different fragments. Here we have three fragments, so we define three different fragment interfaces: / bottomtabdemo / SRC / COM / Xiaowu / bottomtab / demo / zhidaofragment.java / bottomtabdemo / SRC / COM / Xiaowu / bottomtab / demo / iwantknowfragment.java / bottomtabdemo / SRC / COM / Xiaowu / mefragment.java
Each fragment corresponds to a different layout file: / bottomtabdemo / RES / layout / main_ tab1_ fragment.xml /BottomTabDemo/res/layout/main_ tab2_ fragment.xml /BottomTabDemo/res/layout/main_ tab3_ fragment.xml
OK, after these are defined, we will write switching code on the main interface. How to switch fragments? Define the following methods:
The complete code is as follows: / bottomtabdemo / SRC / COM / Xiaowu / bottomtab / demo / mainactivity.java
Source code download: http://xiazai.jb51.net/201612/yuanma/AndroidBottomTab (jb51.net).rar
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.