android项目开发首页+底部导航
来源:互联网 发布:vb中对象的属性 编辑:程序博客网 时间:2024/05/20 11:52
package com.test.main.myframe;import android.app.Activity;import android.app.FragmentManager;import android.app.FragmentTransaction;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.widget.TextView;public class MainActivity extends Activity implements View.OnClickListener{ private TextView tte1; private TextView tte2; private TextView tte3; private TextView tte4; private FragmentManager af; private FirstFragment firstFragment; private SecondFragment secondFragment; private ThreeFragment threeFragment; private FourFragment fourFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); af=getFragmentManager(); setTabSelection(0); } private void setTabSelection(int index) { resetTab(); FragmentTransaction beginTransaction = af.beginTransaction(); hideFragment(beginTransaction); switch (index){ case 0: tte1.setTextColor(Color.BLUE); if(firstFragment==null){ firstFragment=new FirstFragment(); beginTransaction.add(R.id.main_frame,firstFragment); }else { beginTransaction.show(firstFragment); } break; case 1: tte2.setTextColor(Color.BLUE); if(secondFragment==null){ secondFragment=new SecondFragment(); beginTransaction.add(R.id.main_frame,secondFragment); }else { beginTransaction.show(secondFragment); } break; case 2: tte3.setTextColor(Color.BLUE); if(threeFragment==null){ threeFragment=new ThreeFragment(); beginTransaction.add(R.id.main_frame,threeFragment); }else { beginTransaction.show(threeFragment); } break; case 3: tte4.setTextColor(Color.BLUE); if(fourFragment==null){ fourFragment=new FourFragment(); beginTransaction.add(R.id.main_frame,fourFragment); }else { beginTransaction.show(fourFragment); } break; } beginTransaction.commit(); } private void hideFragment(FragmentTransaction beginTransaction) { if(firstFragment!=null){ beginTransaction.hide(firstFragment); } if(secondFragment!=null){ beginTransaction.hide(secondFragment); } if(threeFragment!=null){ beginTransaction.hide(threeFragment); } if(fourFragment!=null){ beginTransaction.hide(fourFragment); } } private void resetTab() { tte1.setTextColor(Color.GREEN); tte2.setTextColor(Color.GREEN); tte3.setTextColor(Color.GREEN); tte4.setTextColor(Color.GREEN); } private void init() { tte1=(TextView)findViewById(R.id.tte1); tte2=(TextView)findViewById(R.id.tte2); tte3=(TextView)findViewById(R.id.tte3); tte4=(TextView)findViewById(R.id.tte4); tte1.setOnClickListener(this); tte2.setOnClickListener(this); tte3.setOnClickListener(this); tte4.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.tte1: setTabSelection(0); break; case R.id.tte2: setTabSelection(1); break; case R.id.tte3: setTabSelection(2); break; case R.id.tte4: setTabSelection(3); break; } }}
0 0
- android项目开发首页+底部导航
- Android开发 ActivityGroupd应用底部导航栏
- android底部导航栏
- Android 通用底部导航
- android底部导航栏
- android之底部导航
- android 底部导航总结
- Android底部导航栏
- android 底部导航栏
- android底部导航栏
- Android BottomNavigationView 底部导航
- Android仿微信底部导航
- Android底部导航总结
- Android底部导航总结
- android 底部导航总结
- 底部导航栏(自定义View+ViewPager实现) android项目详解
- Android小项目之底部导航(RadioButton&Fragment&ViewPager)
- Android项目常用内容之底部ViewPager滑动导航
- 决策树和基于决策树的集成方法(DT,RF,GBDT,XGB)复习总结
- Visual Studio 2012 代码块注释快捷键和格式化快捷键
- java编程思想-面向对象编程的理解
- [bzoj3188]Upit
- 三台服务器安装JDK
- android项目开发首页+底部导航
- Android开发之webview的加载优化
- 数据库基础知识整理:
- JS中的call()和apply()方法
- C语言学习笔记
- 从零到日志采集索引可视化、监控报警、rpc trace跟踪-系统上下线监控
- JavaScript模拟手势翻页动作
- PX EM REM之间的区别
- python2.7中用numpy.reshape 对图像进行切割