Android仿微信页面底部导航效果代码实现
更新时间:2016年09月07日 14:46:11 作者:时代新人
本文给大家分享一段代码有关android仿微信页面底部导航效果代码实现的思路,非常不错,感兴趣的朋友一起看看吧
大家在参考本地代码的时候要根据需要适当的修改,里面有冗余代码小编没有删除。好了,废话不多说了,一切让代码说话吧!
关键代码如下所示:
.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的index private int keyBackClickCount = 0; 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; 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; } } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); isForeground = false; } @Override protected void onDestroy() { // TODO Auto-generated method stub super.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() { @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(); 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)); // 添加显示第一个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); // 把当前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" > <!-- 普通底部导航 --> <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" 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_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>
以上所述是小编给大家介绍的Android仿微信页面底部导航效果代码实现,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
相关文章
Android HttpURLConnection.getResponseCode()错误解决方法
在使用HttpURLConnection.getResponseCode()的时候直接报错是IOException错误,一直想不明白,同一个程序我调用了两次,结果有一个链接一直OK,另一个却一直报这个错误2013-06-06Android基于ViewFilpper实现文字LED显示效果示例
这篇文章主要介绍了Android基于ViewFilpper实现文字LED显示效果,结合完整实例形式分析了Android使用ViewFilpper实现文字LED显示动画效果的相关步骤与实现技巧,需要的朋友可以参考下2017-08-08Android实现登陆页logo随键盘收放动态伸缩(完美解决键盘弹出遮挡控件的问题)
这篇文章主要介绍了Android实现登陆页logo随键盘收放动态伸缩(完美解决键盘弹出遮挡控件的问题)的相关资料,本文介绍的非常详细,具有参考借鉴价值,需要的朋友可以参考下2016-09-09Android静默安装实现方案 仿360手机助手秒装和智能安装功能
这篇文章主要介绍了Android静默安装实现方案,仿360手机助手秒装和智能安装功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2016-11-11
最新评论