国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android仿微信頁面底部導航效果代碼實現

2019-12-12 05:21:24
字體:
來源:轉載
供稿:網友

大家在參考本地代碼的時候要根據需要適當的修改,里面有冗余代碼小編沒有刪除。好了,廢話不多說了,一切讓代碼說話吧!

關鍵代碼如下所示:

.java里面的主要代碼

public class MainActivity extends BaseActivity implements TabChangeListener {private Fragment[] fragments;private FragZaiXianYuYue 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;// 當前fragment的indexprivate int keyBackClickCount = 0;private int indexChange;private boolean isChangeTab = false;@Overrideprotected void onCreate(Bundle arg0) {// TODO Auto-generated method stubsuper.onCreate(arg0);setContentView(R.layout.mainactivity);initView();initTabView();FragBYRecord.setTabChangeListener(this);FragWXRecord.setTabChangeListener(this);registerMessageReceiver();}@Overrideprotected void onResume() {// TODO Auto-generated method stubsuper.onResume();isForeground = true;requestMaintenance();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;}}@Overrideprotected void onPause() {// TODO Auto-generated method stubsuper.onPause();isForeground = false;}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();if(null != mMessageReceiver)unregisterReceiver(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() {@Overridepublic void onClick(View arg0) {Intent intent = new Intent(MainActivity.this,MineActivity.class);MineActivity.mFragValue = MineActivity.FRAG_SYSTEMMESSAGE;startActivity(intent);}});tv_left.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {fragMe.addNewCar();}});}private void initTabView() {fragZaiXianYuYue = new FragZaiXianYuYue();fragDaoLuJiuYuan = new FragDaoLuJiuYuan();fragJiFenShangCheng = 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));// 添加顯示第一個fragmentgetSupportFragmentManager().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);// 把當前tab設為選中狀態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" ><!-- 普通底部導航 --><LinearLayoutandroid:id="@+id/main_bottom"android:layout_width="match_parent"android:layout_height="54dp"android:gravity="center_vertical"android:orientation="horizontal" ><RelativeLayoutandroid:id="@+id/re_zzyy"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:onClick="onTabClicked"android:padding="3dp" ><RelativeLayoutandroid:layout_width="60dp"android:layout_height="match_parent"android:layout_centerHorizontal="true"android:gravity="center" ><ImageViewandroid: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" /><TextViewandroid: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><RelativeLayoutandroid:id="@+id/re_dljy"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:onClick="onTabClicked"android:padding="3dp" ><RelativeLayoutandroid:layout_width="60dp"android:layout_height="match_parent"android:layout_centerHorizontal="true"android:gravity="center" ><ImageViewandroid: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" /><TextViewandroid: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><RelativeLayoutandroid:id="@+id/re_jfsc"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:onClick="onTabClicked"android:padding="3dp" ><RelativeLayoutandroid:layout_width="60dp"android:layout_height="match_parent"android:layout_centerHorizontal="true"android:gravity="center" ><ImageViewandroid: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" /><TextViewandroid: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><RelativeLayoutandroid:id="@+id/re_me"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1"android:onClick="onTabClicked"android:padding="3dp" ><RelativeLayoutandroid:layout_width="60dp"android:layout_height="match_parent"android:layout_centerHorizontal="true"android:gravity="center" ><ImageViewandroid: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" /><ImageViewandroid: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" /><TextViewandroid: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>

以上所述是小編給大家介紹的Android仿微信頁面底部導航效果代碼實現,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南京市| 钟祥市| 万州区| 芜湖县| 同德县| 耒阳市| 静海县| 东乡| 象山县| 乐昌市| 屏东市| 金寨县| 军事| 鄯善县| 商河县| 北海市| 舟曲县| 伽师县| 贵溪市| 阳新县| 河南省| 尚义县| 苗栗县| 白山市| 石河子市| 句容市| 临沧市| 庆安县| 紫金县| 朔州市| 瓮安县| 高邑县| 徐水县| 潜江市| 环江| 亳州市| 滨州市| 晴隆县| 赤城县| 乌拉特后旗| 柞水县|