From 2823c8da2a37347b6c69bb38544d1a166f806516 Mon Sep 17 00:00:00 2001 From: Toyga <330282372@qq.com> Date: Tue, 9 Nov 2021 14:45:20 +0800 Subject: [PATCH] MainActivity Finished! --- .../example/leudaemialikeme/MainActivity.java | 111 ++++++++++++++++++ .../app/src/main/res/layout/bottom.xml | 16 ++- .../res/mipmap-mdpi/img_community_normal.png | Bin 0 -> 522 bytes .../res/mipmap-mdpi/img_community_pressed.png | Bin 0 -> 543 bytes .../main/res/mipmap-mdpi/img_home_normal.png | Bin 0 -> 653 bytes .../main/res/mipmap-mdpi/img_home_pressed.png | Bin 0 -> 674 bytes .../res/mipmap-mdpi/img_message_normal.png | Bin 0 -> 728 bytes .../res/mipmap-mdpi/img_message_pressed.png | Bin 0 -> 764 bytes .../main/res/mipmap-mdpi/img_my_normal.png | Bin 0 -> 554 bytes .../main/res/mipmap-mdpi/img_my_pressed.png | Bin 0 -> 571 bytes .../app/src/main/res/values/colors.xml | 3 + 11 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_community_normal.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_community_pressed.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_home_normal.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_home_pressed.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_message_normal.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_message_pressed.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_my_normal.png create mode 100644 Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_my_pressed.png diff --git a/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/MainActivity.java b/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/MainActivity.java index 2502406..e2f9ca3 100644 --- a/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/MainActivity.java +++ b/Code/LeudaemiaLikeMe/app/src/main/java/com/example/leudaemialikeme/MainActivity.java @@ -1,13 +1,17 @@ package com.example.leudaemialikeme; import android.os.Bundle; +import android.view.View; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; +import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { @@ -28,11 +32,118 @@ public class MainActivity extends AppCompatActivity { private TextView textCommunity; private TextView textMessage; private TextView textMy; + //底部导航点击事件监听器 + private View.OnClickListener onClickListener = new View.OnClickListener() { + public void onClick(View v) { + //先将四个 ImageButton 置为灰色 + resetImgs(); + //根据点击的 Tab 切换不同的页面及设置对应的 ImageButton 为绿色 + switch (v.getId()) { + case R.id.tab_home: + selectTab(0); + break; + case R.id.tab_community: + selectTab(1); + break; + case R.id.tab_message: + selectTab(2); + break; + case R.id.tab_my: + selectTab(3); + break; + } + } + }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + getSupportActionBar().hide(); setContentView(R.layout.activity_main); + initFragments(); //初始化数据 + initViews(); //初始化控件 + initEvents(); //初始化事件 + initFirstRun(0);//第一次运行初始化界面,第一个碎片 + } + + private void initFirstRun(int i) { + resetImgs(); //重置所有 Tab + selectTab(i); //显示第 i 个碎片 + } + + private void selectTab(int i) { + //根据点击的 Tab 设置对应的 ImageButton 为绿色 + switch (i) { + case 0: + imgHome.setImageResource(R.mipmap.img_home_pressed); + textHome.setTextColor(getResources().getColor(R.color.hair_grey)); + break; + case 1: + imgCommunity.setImageResource(R.mipmap.img_community_pressed); + textCommunity.setTextColor(getResources().getColor(R.color.hair_grey)); + break; + case 2: + imgMessage.setImageResource(R.mipmap.img_message_pressed); + textMessage.setTextColor(getResources().getColor(R.color.hair_grey)); + break; + case 3: + imgMy.setImageResource(R.mipmap.img_my_pressed); + textMy.setTextColor(getResources().getColor(R.color.hair_grey)); + break; + } + //设置当前点击的 Tab 所对应的页面 + setCurrentFragment(i); + } + + private void setCurrentFragment(int i) { + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction trans = fm.beginTransaction(); + trans.replace(R.id.frag_layout, fragmentList.get(i)); + trans.commit(); + //Log.e("fragment", "ok"); + } + + private void resetImgs() { + imgHome.setImageResource(R.mipmap.img_home_normal); + imgCommunity.setImageResource(R.mipmap.img_community_normal); + imgMessage.setImageResource(R.mipmap.img_message_normal); + imgMy.setImageResource(R.mipmap.img_my_normal); + textHome.setTextColor(getResources().getColor(R.color.light_grey)); + textCommunity.setTextColor(getResources().getColor(R.color.light_grey)); + textMessage.setTextColor(getResources().getColor(R.color.light_grey)); + textMy.setTextColor(getResources().getColor(R.color.light_grey)); + } + + private void initEvents() { + tabHome.setOnClickListener(onClickListener); + tabCommunity.setOnClickListener(onClickListener); + tabMessage.setOnClickListener(onClickListener); + tabMy.setOnClickListener(onClickListener); + + } + + private void initViews() { + tabHome = (LinearLayout)findViewById(R.id.tab_home); + tabCommunity = (LinearLayout)findViewById(R.id.tab_community); + tabMessage = (LinearLayout)findViewById(R.id.tab_message); + tabMy = (LinearLayout)findViewById(R.id.tab_my); + imgHome = (ImageButton)findViewById(R.id.tab_home_img); + imgCommunity = (ImageButton)findViewById(R.id.tab_community_img); + imgMessage = (ImageButton)findViewById(R.id.tab_message_img); + imgMy = (ImageButton)findViewById(R.id.tab_my_img); + textHome = (TextView)findViewById(R.id.tab_home_text); + textCommunity = (TextView)findViewById(R.id.tab_community_text); + textMessage = (TextView)findViewById(R.id.tab_message_text); + textMy = (TextView)findViewById(R.id.tab_my_text); + + } + + private void initFragments() { + fragmentList = new ArrayList(); + fragmentList.add(new IndexFragment()); + fragmentList.add(new CommunityFragment()); + fragmentList.add(new MessageFragment()); + fragmentList.add(new MyFragment()); } } \ No newline at end of file diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/layout/bottom.xml b/Code/LeudaemiaLikeMe/app/src/main/res/layout/bottom.xml index 5c56f3b..7b3e7e8 100644 --- a/Code/LeudaemiaLikeMe/app/src/main/res/layout/bottom.xml +++ b/Code/LeudaemiaLikeMe/app/src/main/res/layout/bottom.xml @@ -17,10 +17,11 @@ android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:src="@mipmap/tab_home_pressed" + android:src="@mipmap/img_home_pressed" + android:background="@color/white" /> @@ -37,7 +38,8 @@ android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:src="@mipmap/tab_video_normal" /> + android:background="@color/white" + android:src="@mipmap/img_community_normal" /> + android:background="@color/white" + android:src="@mipmap/img_message_normal" /> @@ -75,7 +78,8 @@ android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:src="@mipmap/tab_my_normal" /> + android:background="@color/white" + android:src="@mipmap/img_my_normal" /> igP)Px$#7RU!R9Hvtm%mB_K@i5j*-NFBjTROuECi#3>|U@EwX(7hM6i`$;WG&8L--g0 zNoS>nppe~_h+3wwP_W7agk8B{f|tbeb~QN#uev`o-}l>@y0j92qAi{@0|Pt zBvrr|bK=vUAP81J+gGVuKtz|E^K~D9q&F)yKxCY01$}-R z0G54LJ?l35lq{Ie#1gcppr%n~J+cTI&U4%$l`!`eT0? zWAgwu08AzHy=IKL?SCEw!8zyrdRU&*pOKVuiHHsX?DUDfSZfc$Fg$bJluiI$aVcfx z9V8E+${4GZN~M;oc@*yj5G6_}C#<#e<#KtTPx$*-1n}R9Hvtm%lH>U>L{0Pu)aFEDVMl443#Z8$|DJG8rTyvC3VEO|F+1B$$;= zoLc+?mk5*Tv>_}a5sU@{iOEd7kLWp3cdGB}TuF3m`##_A=Y5{1?NdU;2Sx0UDuC(3 z<&LLEiZgRdz2LOi)0I6mcU?=*2VgkX4uFw*8Nb&d;6x*yT-WnwAFh{A4R_@n%)LKh z{$5jyac5yLe^Ky+d2xjq$utYfVaFjFfwJOFSn1dpl!5RpNIiSGiacz+oq zlYuYAR2KX~0M|MOV?bp$(lLY^TQ|G>^FTum3t9SA=Cc%KM+8>#$JtvIPaBg0wkCy03l#{FV+ z3&AsX+T50HN-2PfxZzqE0P|qP0WLm>SY|6ddoOG5eKS;oynfkTY}VRZ6NO~1D&;bo h$^bGZL2Dxicm^FKydkwY+(`fc002ovPDHLkV1kDa=p_IE literal 0 HcmV?d00001 diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_home_normal.png b/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_home_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..c6fc92c3f4373f2a9709f3de4900a17e92b1dc1c GIT binary patch literal 653 zcmV;80&@L{P)Px%M@d9MR9HvtmA`8gK@`W|o4Lb75NrhPOd%+T2Rk!cC;1OV2&S<+Y~%zXqMh0) z90&$ctgIvwNG}#i>YdpY5&Kd~QwC8AptW8>#FqfjN{hY$fJ;iLUqwZ=*2fuR z&xq)18vj8=eWldqG>EAHaU9`iTwAj3*!5NF&6uL z=UkzKl>k!8%0?{%njGV!2cWe+PeiNfT-Z=beJFC`P#hSIMyJQ)@#m~yr_(vp?RLN9 zAr1vVYyB7z2U#&9T31Tl_$L5y9B&iR{wmI#^&KI^@*LpkIp7CK{;fFYi$y(Pt=-M% zPIf}0L8P_5h=}j%j@&wVMATDCy|1+ke3CKd2>`4Bz^OU{B{^RKU{gwYz4kUdpkSlN n5430+DNRY91I!(mxdXoe5-wjb>Z|A(00000NkvXXu0mjfPx%TuDShR9HvtmAz}!a2UtG&o5O$6kP<}>>%i%pnEULA0QN=*hO%-ON(+sy`0*~ zbMoa<3oY8a#G#W^3SFGUA(!sHpo`#8Hw6d9ii7Rtk)%mE(p+AwwxwLA@Oz#-&nMsC z^Fr9>hqgICb~b=!*K1LQ1XgDo>iDP2_T=HcXe*xmH>B3AI`;i<)J#-Ba}16KbzN3T zqJ6}e25=&qd?Ybfa*0#9neKlB^A;vZ+*N@<624KtzRS z04}a2pf(7)|H?1`_JIg&H05eFD@0y^FzylodQ;XHyn_+PxWMor&>uJ~NMfZpGcf)w z4J1DRks}ym4Y~5BGx(@8an>bFf>{pE-?{?DCjaB*4SLP?|GU{X=X)hU5HS zDsaVqaCB9O&z%YTT=&>x^~RSd#DBShQp=bkLb)>;Go~#?zqU01i-t`Me-(!h6Ixb5 zS9<`vPXTX&MgNK=lH+QC+U#s-#c(I&YD4GYX~2D#b>wFA6K72M`uj|~z;h}&#v_1- z2y`S{f_N_me+6jXlJ%>Zx8Y_I=KXe4izaWfo&r4ucBBG-05Xz9Ff@ypd;kCd07*qo IM6N<$f~gob{{R30 literal 0 HcmV?d00001 diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_message_normal.png b/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_message_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..f141d189244c1fa4dcc169e48c4b7f4ea5160c82 GIT binary patch literal 728 zcmV;}0w?{6P)Px%l1W5CR9Hvtmpy1xQ546|KOYhVJBf&bgPX>t$-8|SMHIwYp@X1KE)IS)($?Vt#PlWu;DDh`qkb;^79H6T?dk%EJQ?t$DRC)`)k($?3nWa-`R%Q@%&d*^@N zgpOJ zq6_N*!OX9XG5z^`e%AB6tpKhO(N*b2D}ZQK;_-MPo6QEc8)pTKh_#8-nUpz6adNlVJ&%MA^Mp4E`YrYivDEgVsCHnGaGl9h(tWI6mV34 zFn>fTRcaZgG7%kr>49yb}NbPB(AGa*j6|jSagAFZOcrc>I^+I5V67jQ#-+*-J||Ly|%O0000< KMNUMnLSTXt^;Dh! literal 0 HcmV?d00001 diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_message_pressed.png b/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_message_pressed.png new file mode 100644 index 0000000000000000000000000000000000000000..b1976be6e026b3ffb73d4f8dffba590b179a213f GIT binary patch literal 764 zcmVPx%wn;=mR9HvtmoZG#U=+vyuRR9xoZQPiHkver162o-MMK}rf%JgVSVOw>TMH7db()xm0PNf_7>{#yL%Oxy`7<+Vqw&;z*^;6WS5-2Zad?#wZxwKRA(nn1#U0}e zKtgEi8 z+W_|dQFI1`ZabP9^LLYROz|y0_*dXS0M%^L?U%EK!GTyp@7t3i4T!gz#96Wgh2vae2^S9^(|sLGGd;iDb1I_t`eTbBp;a-ezw zAmLgTF}DUvkU{*avP+&W&S`ed{mjC0J`uQ<-vZMFpao9)708^i<7q=qxnrJU*>B#n zsyfmE$1n(#T2-|4Bps^<;B06B3CFxi!1d4ok|pB?h&saqa4a3*?$7`dCG#v1?u7xsjC1l- uEWYFAGH={Tc$w9yDt#J>rlz<4jD7-*tT((Y-1&q60000Px$kb{Fmu=5|V zvJnosYs6XdS*Im{7JcPEqOf^gI9!o2S{-@ci7GfT|b zvMlS8+yrn9fP20N@Hvj-e!Jav?{hW!M)!KX%k_Hwk%)8)G;bP>Mz`5)9{F;;3}~%) z06g`ElB-Io1E2U(1B1cfLZ0W}ePGiVk{^^(H+(du2DH|%0o?I{&BlnxPMW5BWx7HG zAzwc;;FlyxHWo6_@At1qQS`A4@~{3{t+w83wZ=vI!VDN=wnbz=)BwqQN~!1nuYsjc z!O|C@o4ciMLuVi)3zZh4Us+gQDV}bjEX%Hvd;#F%sUJqu0Y{_J%49Nm2w+`A)<~|M z+Ho9OjLLMShfx_|(f&US42Q#W*4hng?GEoa~XIC;AVh$VF}4kE(1SEo?n<21~_mTkT7jE ssxt#;8K5!dWyv3JHLL9}6jzde0`3#bNYehx{{R3007*qoM6N<$g4$mD3;+NC literal 0 HcmV?d00001 diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_my_pressed.png b/Code/LeudaemiaLikeMe/app/src/main/res/mipmap-mdpi/img_my_pressed.png new file mode 100644 index 0000000000000000000000000000000000000000..4985794134c3eb2230e9f53f9000061ba1775fbe GIT binary patch literal 571 zcmV-B0>u4^P)Px$^+`lQR9Hvtm$7RUK@`TnFLxwDx)chgvCt&MKfoNwUK&LU8{yJf#hW__hG0%? zEv&rV6I61r5p5+Qm4!rNvbTXW`2*tBS_tVBgbT zyF|*N0*Gce}dkJ#igi-BsJ%*8i+%KY^S;+A!J~%>Zy?F@*z5;OW*qhP8g40{A zp~5$PAA&K6jDj3JwsvfL871iwn^6)V>---EZml*4PYrM!qAwDRtGDsmEV4_@_xkgf zu7Bgf*Tcf!3{(U6I)Eo6&KuLy1%3eKk?-8=ecbd6sL*>1k-2m{%V=WRcN$ZX`iFs9 z=(a^rx5U}Wh^p^2p0l>ux+Yq`v7=;DY0VO=fg9EQPBxUCT7U(rj<*WPRXapBl@I|{ z;C=#eCL795Es$NRjw^QZqfwn0ILQE2=q@Gv@gB`?`x}K={tjmE!Zni|3{(IB002ov JPDHLkV1hYh3o!ry literal 0 HcmV?d00001 diff --git a/Code/LeudaemiaLikeMe/app/src/main/res/values/colors.xml b/Code/LeudaemiaLikeMe/app/src/main/res/values/colors.xml index d2cd14a..02826a4 100644 --- a/Code/LeudaemiaLikeMe/app/src/main/res/values/colors.xml +++ b/Code/LeudaemiaLikeMe/app/src/main/res/values/colors.xml @@ -3,4 +3,7 @@ #008577 #00574B #D81B60 + #cdcdcd + #66c18c + #fff \ No newline at end of file