0. The content page does not use the usual fragment. Instead, it adopts a direct inheritance method, which is considered simpler.
1. Use inheritance for reuse. 2. The base class handles the large page layout and the bottom navigation display as well as the logic. 3. Use linear layout. Split. TV Center. Fixed font. 4. Controls use styles to centralize properties. There are branching cases that are handled using Dranable's selecter. Very concise and clear.
View Layout
<?xml version="1.0"encoding="Utf-8"? ><relativelayout xmlns:android="http://schemas.android.com/apk/res/android"Android:layout_width="match_parent"android:layout_height="match_parent"><linearlayout android:orientation="Horizontal"Android:id="@+id/bottommenu"Android:layout_width="match_parent"android:layout_height="56DP"Android:layout_alignparentbottom="true"android:layout_alignparentleft="true"android:paddingleft="1DP"android:paddingright="1DP"> <textview android:id="@+id/tvmenucategory1"style="@style/bottommenu"android:drawabletop="@drawable/category"android:text="@string/bottommenu1"/> <textview android:id="@+id/tvmenucategory2"style="@style/bottommenu"android:drawabletop="@drawable/book"android:text="@string/bottommenu2"/> <textview android:id="@+id/tvmenucategory3"style="@style/bottommenu"android:drawabletop="@drawable/book"android:text="@string/bottommenu3"/> <textview android:id="@+id/tvmenucategory4"style="@style/bottommenu"android:drawabletop="@drawable/book"android:text="@string/bottommenu4"/> <textview android:id="@+id/tvmenucategory5"style="@style/bottommenu"android:drawabletop="@drawable/book"android:text="@string/bottommenu5"/></linearlayout> <relativelayout android:id="@+id/rlayoutcontent"Android:layout_width="match_parent"android:layout_height="0DP"Android:layout_above="@id/bottommenu"android:layout_alignparentleft="true"android:layout_alignparenttop="true"android:layout_marginleft="0DP"android:layout_margintop="0DP"Android:layout_marginbottom="0DP"></RelativeLayout></RelativeLayout>Style uniform style & drawnable selector to deal with the difference.
<!--page master page--><style name="Bottommenu"> <item name="android:gravity">center</item> <item name="Android:layout_width">match_parent</item> <item name="Android:layout_height">match_parent</item> <item name="Android:layout_weight">1</item> <item name="Android:textcolor"> @drawable/selector_bottommenu</item></style><?xml version="1.0"encoding="Utf-8"? ><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="@color/color_green"Android:state_selected="true"/> <item android:color="@color/color_green"Android:state_checked="true"/> <item android:color="@color/color_grey"/></selector> activity. Package Com.android.linson.catshome.control;import Android.app.activity;import Android.os.bundle;import Android.support.annotation.nullable;import Android.util.log;import Android.view.view;import Android.widget.relativelayout;import Android.widget.textview;import COM.ANDROID.LINSON.CATSHOME.R;//1. Implement the overall layout, leaving the main page to populate the derived class. //2. Implement the bottom menu function. The bottom logic is all in the base class here. Public classMasterPage extends Activity implements textview.onclicklistener{//Control PrivateRelativelayout mcontent; PrivateTextView mTVMenu1; PrivateTextView mTVMenu2; PrivateTextView MTVMenu3; PrivateTextView MTVMenu4; PrivateTextView MTVMenu5; //Data PrivateString tag="DEBUG"; PrivateTextView Mselectedmenu; @Overrideprotected voidonCreate (@Nullable Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.masterpage); FindControls (); Mselectedmenu=mTVMenu1; Flushmenuselected (); Mtvmenu1.setonclicklistener ( This); Mtvmenu2.setonclicklistener ( This); Mtvmenu3.setonclicklistener ( This); Mtvmenu4.setonclicklistener ( This); Mtvmenu5.setonclicklistener ( This); } Private voidFindControls () {mcontent=Findviewbyid (r.id.rlayoutcontent); MTVMenu1=Findviewbyid (R.id.tvmenucategory1); MTVMENU2=Findviewbyid (R.id.tvmenucategory2); MTVMENU3=Findviewbyid (R.id.tvmenucategory3); MTVMenu4=Findviewbyid (R.ID.TVMENUCATEGORY4); MTVMenu5=Findviewbyid (R.id.tvmenucategory5); } @Override Public voidOnClick (View v) {if(v instanceof TextView) {TextView TEMPTV=(TextView) v; Mselectedmenu=TEMPTV; Flushmenuselected (); Switch(Temptv.getid ()) { Caser.id.tvmenucategory1: { Break; } } } } Private voidflushmenuselected () {mtvmenu1.setselected (false); Mtvmenu2.setselected (false); Mtvmenu3.setselected (false); Mtvmenu4.setselected (false); Mtvmenu5.setselected (false); Mselectedmenu.setselected (true); }}
Cathome Cat Home Development Diary-bottom navigation