Android Imitation micro-letter page bottom navigation effect code implementation _android

Source: Internet
Author: User
Tags commit getcolor stub

When you refer to the local code should be based on the need for appropriate changes, there are redundant code small series did not delete. OK, nonsense not to say, everything let the code speak!

The key code looks like this:

The main code inside Java

public class Mainactivity extends Baseactivity implements Tabchangelistener {private fragment[] fragments private Fragz
Aixianyuyue Fragzaixianyuyue;
Private Fragdaolujiuyuan Fragdaolujiuyuan;
Private Fragjifenshangcheng Fragjifenshangcheng;
Private Fragme Fragme;
Private ImageView img_right;
Private imageview[] imagebuttons;
Private ImageView img_me_notity;
Private textview[] textviews;
private int index;
private int currenttabindex;//the index private int keybackclickcount = 0 of the current fragment;
private int indexchange;
Private Boolean ischangetab = false; @Override protected void OnCreate (Bundle arg0) {//TODO auto-generated Method Stub super.oncreate (arg0); Setcontentview (R
. layout.mainactivity);
Initview ();
Inittabview ();
Fragbyrecord.settabchangelistener (this);
Fragwxrecord.settabchangelistener (this);
Registermessagereceiver (); @Override protected void Onresume () {//TODO auto-generated Method Stub super.onresume (); isforeground = true; requestm
Aintenance (); if (Ischangetab) {if (IndExChange = = 0) {viewtitle.setzhongjiantext (R.STRING.FRAG_ZXYY); tv_left.setvisibility (view.gone);} else if ( Indexchange = = 0) {viewtitle.setzhongjiantext (R.STRING.FRAG_DLJY); tv_left.setvisibility (View.GONE);} changeTab (
Indexchange);
Ischangetab = false; } @Override protected void OnPause () {//TODO auto-generated Method Stub super.onpause (); isforeground = false;} @Over Ride protected void OnDestroy () {//TODO auto-generated Method Stub Super.ondestroy (); if (null!= mmessagereceiver) Unreg
Isterreceiver (Mmessagereceiver); 
private void Initview () {viewtitle = (viewtitle) Findviewbyid (r.id.title_bar); img_right = Viewtitle.getyoubianview ();
Img_right.setvisibility (view.visible);
Tv_left = Viewtitle.getzuobiantextview ();
Viewtitle.getzuobianview (). setvisibility (View.gone);
Tv_left.settext ("XXXX"); Img_right.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View arg0) {Intent Intent = new Intent
(Mainactivity.this, Mineactivity.class); Mineactivity.mfragvaLue = Mineactivity.frag_systemmessage;
StartActivity (Intent);
}
});
Tv_left.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View arg0) {Fragme.addnewcar ();}}); private void Inittabview () {Fragzaixianyuyue = new Fragzaixianyuyue (); Fragdaolujiuyuan = new Fragdaolujiuyuan (); FragJ
Ifenshangcheng = new Fragjifenshangcheng ();
Fragme = new Fragme ();
Fragments = new fragment[] {Fragzaixianyuyue, Fragdaolujiuyuan, Fragjifenshangcheng, Fragme};
Imagebuttons = new Imageview[4];
Imagebuttons[0] = (ImageView) Findviewbyid (R.ID.IB_ZZYY);
IMAGEBUTTONS[1] = (ImageView) Findviewbyid (R.ID.IB_DLJY);
IMAGEBUTTONS[2] = (ImageView) Findviewbyid (R.ID.IB_JFSC);
IMAGEBUTTONS[3] = (ImageView) Findviewbyid (R.id.ib_me);
Img_me_notity = (ImageView) Findviewbyid (r.id.ib_me_notity);
Imagebuttons[0].setselected (TRUE);
Viewtitle.setzhongjiantext (R.STRING.FRAG_ZXYY);
Textviews = new Textview[4];
Textviews[0] = (TextView) Findviewbyid (R.ID.TV_IB_ZZYY); TEXTVIEWS[1] = (TextView) findviewByid (R.ID.TV_DLJY);
TEXTVIEWS[2] = (TextView) Findviewbyid (R.ID.TV_JFSC);
TEXTVIEWS[3] = (TextView) Findviewbyid (R.id.tv_me);
Textviews[0]. SetTextColor (Getresources (). GetColor (R.color.color_yellow)); Add displays the first fragment Getsupportfragmentmanager (). BeginTransaction (). Add (R.id.fragment_container, Fragzaixianyuyue). Add (R.id.fragment_container, Fragdaolujiuyuan). Add (R.id.fragment_container, Fragjifenshangcheng). Add ( R.id.fragment_container, Fragme). Hide (Fragdaolujiuyuan). Hide (Fragjifenshangcheng). Hide (Fragme). Show (
Fragzaixianyuyue). commit (); public void ontabclicked (view view) {switch (View.getid ()) {case R.id.re_zzyy:index = 0; if (Fragzaixianyuyue!= null
) {} viewtitle.setzhongjiantext (R.STRING.FRAG_ZXYY);
Tv_left.setvisibility (View.gone);
Changetab (index);
Break
Case R.id.re_dljy:index = 1;
Viewtitle.setzhongjiantext (R.STRING.FRAG_DLJY);
Tv_left.setvisibility (View.gone);
Changetab (index);
Break Case R.id.re_jfsc:if (Sharepreferutil.getboolean (Commonstring.haveservice, FalsE) {index = 2; Viewtitle.setzhongjiantext (R.STRING.FRAG_JFSC); tv_left.setvisibility (View.gone);
Fragjifenshangcheng.requestjudgecar ();
Changetab (2);
if (Sharepreferutil.getboolean ("Isfristgoshop", True)) {Sharepreferutil.putboolean ("Isfristgoshop", false);
Fragjifenshangcheng.mengcengdialog ();
}else{Showaddservicedialog ();} break;
Case R.id.re_me:index = 3;
Viewtitle.setzhongjiantext (R.string.frag_me);
Tv_left.setvisibility (view.visible);
Changetab (index);
Break } public void Changetab (int index) {if (Currenttabindex!= index) {fragmenttransaction TRX = Getsupportfragmentmanager
(). BeginTransaction ();
Trx.hide (Fragments[currenttabindex]); if (!fragments[index].isadded ()) {Trx.add (R.id.fragment_container, Fragments[index]), Trx.show (Fragments[index)).
Commit ();
} imagebuttons[currenttabindex].setselected (FALSE);
Sets the current tab to the selected state imagebuttons[index].setselected (true);
Textviews[currenttabindex].settextcolor (Getresources (). GetColor (R.color.white)); Textviews[index].settextcolor (Getresources (). GetColor (R.color.color_yellow));
Currenttabindex = index; } mainactivity.xml: <include layout= "@layout/layout_bottom"/> layout_bottom.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= "Wrap_content" android:layout_alignparentbottom= "true" Android: background= "@color/black" android:orientation= "vertical" > <!--normal bottom navigation--> <linearlayout android:id= "@+id
/main_bottom "android:layout_width=" match_parent "android:layout_height=" 54DP "android:gravity=" center_vertical "
android:orientation= "Horizontal" > <relativelayout android:id= "@+id/re_zzyy" android:layout_width= "0DP" android:layout_height= "Match_parent" android:layout_weight= "1" android:onclick= "ontabclicked" 3DP "> <relativelayout android:layout_width=" 60dp "android:layout_height=" Match_parent "Android:layout_ Centerhorizontal= "true" android:gravity= "center" > <imageview android:id= "@+id/ib_zzyy" android:layout_width= "30DP" android:layout_height= "28DP "Android:layout_centerhorizontal=" true "android:focusable=" false "Android:scaletype=" Centerinside "android:src=" @
Drawable/tab_zaixianyuyue "/> <textview android:id= @+id/tv_ib_zzyy" android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" android:layout_below= "@id/ib_zzyy" android:layout_centerhorizontal= "true" android:layout_margintop= "3DP" android:textcolor= "@color/white" android:text= "@string/frag_zxyy" android:textsize = "12SP"/> </RelativeLayout> </RelativeLayout> <relativelayout android:id= "@+id/re_dljy" Android:
Layout_width= "0DP" android:layout_height= "Match_parent" android:layout_weight= "1" android:onclick= "onTabClicked"
android:padding= "3DP" > <relativelayout android:layout_width= "60dp" android:layout_height= "Match_parent" Android:layout_centerhorizontal= "true" android:gravity= "center" > <imageview android:id= "@+Id/ib_dljy "android:layout_width=" 30DP "android:layout_height=" 28DP "android:layout_centerhorizontal=" true " Android:focusable= "false" Android:scaletype= "Centerinside" android:src= "@drawable/tab_daolujiuyuan"/> <
TextView android:id= "@+id/tv_dljy" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:layout_below= "@id/ib_dljy" android:layout_centerhorizontal= "true" android:layout_margintop= "3DP" Android:
Textcolor= "@color/white" android:text= "@string/frag_dljy" android:textsize= "12sp"/> </RelativeLayout> </RelativeLayout> <relativelayout android:id= "@+id/re_jfsc" android:layout_width= "0DP" Android:layout_ height= "Match_parent" android:layout_weight= "1" android:onclick= "ontabclicked" android:padding= "3DP" > < Relativelayout android:layout_width= "60DP" android:layout_height= "Match_parent" android:layout_centerhorizontal= " True "android:gravity=" center > <imageview android:id= "@+id/ib_jfsc" android:layout_width= "30DP" Android:layout_height= "28DP" android:layout_centerhorizontal= "true" android:focusable= "false" android:scaletype= " Centerinside "android:src=" @drawable/tab_jifenshangcheng/> <textview android:id= "@+id/tv_jfsc" Android: Layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_below= "@id/IB_JFSC" Android: Layout_centerhorizontal= "true" android:layout_margintop= "3DP" android:textcolor= "@color/white" android:text= "@
STRING/FRAG_JFSC "android:textsize=" 12sp "/> </RelativeLayout> </RelativeLayout> <relativelayout
Android:id= "@+id/re_me" android:layout_width= "0DP" android:layout_height= "Match_parent" android:layout_weight= "1" android:onclick= "ontabclicked" android:padding= "3DP" > <relativelayout android:layout_width= "60DP" Android:
layout_height= "Match_parent" android:layout_centerhorizontal= "true" android:gravity= "center" > <imageview Android:id= "@+id/ib_me" android:layout_width= "30DP" android:layout_height= "28DP" android:layout_centerhorizontal= "TRue "android:focusable=" false "Android:scaletype=" Centerinside "android:src=" @drawable/tab_me "/> <imageview Android:id= "@+id/ib_me_notity" android:layout_width= "5DP" android:layout_height= "5DP" android:layout_aligntop= "@+" Id/ib_me "android:layout_alignright=" @+id/ib_me "android:scaletype=" Centerinside "android:src=" @drawable/app_34_ Icon_point_normal "android:visibility=" Gone "/> <textview android:id=" @+id/tv_me "android:layout_width=" Wrap_ Content "android:layout_height=" wrap_content "android:layout_below=" @id/ib_me "android:layout_centerhorizontal=" True "android:layout_margintop=" 3DP "android:textcolor=" @color/white "android:text=" @string/frag_me "Android: Textsize= "12SP"/> </RelativeLayout> </RelativeLayout> </LinearLayout> </LinearLayout>

The above is a small series to introduce the Android imitation Micro-letter page navigation effect code to achieve, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.