"declaration"
Welcome reprint, but please keep the original source of the article →_→
Life One number: http://www.cnblogs.com/smyhvae/
Article Source: http://www.cnblogs.com/smyhvae/p/4463931.html
Contact information: smyhvae@163.com
Body
To achieve the bottom tab of the App home page switch has seen four or five ways, first look at the operation of the effect diagram:
Today we will use the Radiogroup method to achieve the following. "Development Environment"
Physical machine version: Win 7 Ultimate Edition (64-bit)
IDE version: Android Studio 1.2 Preview Project file structure: (at the end of this article there is source code)
Homeactivity.java: The entire page interface four fragment.java: corresponding to the four Fragment interface Drawable folder is the corresponding tab and text switch status The remaining XML files are the corresponding activity and fragment layout files. First, the layout file:
(1) Activity_home.xml:HomeActivity layout file
1 <relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" 2 xmlns:tools= "/HTTP/ Schemas.android.com/tools "3 android:layout_width=" match_parent "4 android:layout_height=" match_parent "5 6 Tools:context= ". Mainactivity "> 7 8 <!--tab above the display area--9 <framelayout android:id=" @+id/mhomecontent "11 Android:layout_width= "Match_parent" android:layout_height= "Match_parent" Android:layout_above = "@+id/mhomeradiogroup" > </FrameLayout> four <!--under the <radiogroup 19 tab--> Android:id= "@+id/mhomeradiogroup" android:layout_width= "Match_parent" android:layout_height= "56DP" android:orientation= "Horizontal" android:layout_alignparentbottom= "true" android:b ackground= "@color/tab_bg" > <radiobutton android:id= "@+id/mhomehomerb" 28 Android:layout_widTh= "0DP" android:layout_height= "Wrap_content" android:layout_weight= "1" Andro id:button= "@null" android:gravity= "center" android:text= "@string/home_home" Ndroid:textcolor= "@drawable/selector_tab_text_color" android:background= "@color/tab_bg" oid:drawabletop= "@drawable/selector_tab_home" Notoginseng/>-<radiobutton-Android:id = "@+id/mhomefindrb" android:layout_width= "0DP" android:layout_height= "Wrap_content" 43 android:layout_weight= "1" android:button= "@null" android:gravity= "center" 46 android:text= "@string/home_find" android:textcolor= "@drawable/selector_tab_text_color"
ndroid:background= "@color/tab_bg" android:drawabletop= "@drawable/selector_tab_find"/> 51 <radiobuTton android:id= "@+id/mhomesearchrb" android:layout_width= "0DP" android:layou t_height= "Wrap_content" android:layout_weight= "1" android:button= "@null" oid:gravity= "center" android:text= "@string/home_search" android:textcolor= "@drawable/selecto R_tab_text_color "android:background=" @color/tab_bg "android:drawabletop=" @drawable/selector _tab_search "/>" <radiobutton android:id= "@+id/mhomeprofilerb" 67 Android:layout_width= "0DP" android:layout_height= "Wrap_content" android:layout_weight= " 1 "android:button=" @null "android:gravity=" center "android:text=" @string/Home _profile "android:textcolor=" @drawable/selector_tab_text_color "android:background=" @color/t AB_BG "droid:drawabletop= "@drawable/selector_tab_profile" 76 android:checked= "true"/> </RadioGroup> </RelativeLayout>
Code a bit more, nothing more than a framelayout corresponding to the tab above the display area, and then four RadioButton into a group of radio buttons placed in the Radiogroup.
Line 13: To ensure that the framelayout occupy the rest of the space after the tab.
76 Line: Android:checked= "True" This is important, later in the Java code to say.
RadioButton a bit more properties, we choose to select