下面是安卓开发仿微信界面的代码。

分为3步,第一步是界面的编写,第二步是导航界面,第三步是右上角菜单栏。

开始第一步前先预览一下效果。

第一步,界面。

界面的思路是利用ViewPager+Fragment实现,所以activity_main.xml中添加一个ViewPager。顶部和底部include的顶部栏和底部栏后面再说。

MainActivity的界面activity_main.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="match_parent"android:orientation="vertical"><include layout="@layout/layout_main_top" /><android.support.v4.view.ViewPager
        android:id="@+id/vp_mainvp"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"></android.support.v4.view.ViewPager><TextView
        android:layout_width="match_parent"android:layout_height="0.5dp"android:background="#737373" /><TextView
        android:layout_width="match_parent"android:layout_height="0.7dp"android:background="#101010" /><include layout="@layout/layout_main_bottom" /></LinearLayout>

当然,要用到ViewPager+Fragment就要建立Fragment,如图我建了三个Fragment,这个可以根据需要自己创建。

这三个Fragment很类似,这里写出一个,其他以此类推。

package activity;import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;import com.chase.cn.money_of_my.R;/*** Created by Chase on 2017/2/6.*/public class Fragment_tab01 extends Fragment {@Overridepublic View onCreateView(LayoutInflater inflater,  ViewGroup container,  Bundle savedInstanceState) {View tab01 = inflater.inflate(R.layout.fragment_tab01_home,container,false);return tab01;}
}

此Fragment对应的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="match_parent"android:orientation="vertical"></LinearLayout>

现在回到MainActivity中:

package activity;import ...public class MainActivity extends FragmentActivity {private ViewPager mViewPager;private MyFragmentPagerAdapter mAdapter;private List<Fragment> fragmentList; //保存界面的view@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);StatusBarUtil.setWindowStatusBarColor(this, R.color.colorTitleGray);initViews();initDatas();}/*** 数据初始化*/private void initDatas() {//fragment数据源fragmentList = new ArrayList<Fragment>();fragmentList.add(new Fragment_tab01());fragmentList.add(new Fragment_tab02());fragmentList.add(new Fragment_tab03());mAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragmentList);mViewPager.setAdapter(mAdapter);}/*** 初始化控件*/private void initViews() {mViewPager = (ViewPager) findViewById(R.id.vp_mainvp);}}

需要编写一个ViewPager的Adapter:

package utils;import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;import java.util.List;/*** Created by Chase on 2017/2/6.*/public class MyFragmentPagerAdapter extends FragmentPagerAdapter {private List<Fragment> fragList;private List<String> tabList;public MyFragmentPagerAdapter(FragmentManager fm, List<Fragment> fragList) {super(fm);this.fragList = fragList;}@Overridepublic CharSequence getPageTitle(int position) {return tabList.get(position);}@Overridepublic Fragment getItem(int position) {return fragList.get(position);}@Overridepublic int getCount() {return fragList.size();}
}

现在三个Fragment已经添加到了MainActivity中,滑动ViewPager切换Fragment,同时底部的导航栏也会切换,在为ViewPager添加监听以前,先说说底部导航栏。

第二步,底部导航。

这个的切换其实就是切换准备好的png图片和改变文字的颜色。

下面是刚才导入的底部导航栏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="52dp"android:orientation="horizontal"><LinearLayout
        android:alpha="30"android:id="@+id/ll_taball"android:layout_width="match_parent"android:layout_height="52dp"android:background="#656d78"android:orientation="horizontal"><FrameLayout
            android:id="@+id/fl_page_home"android:layout_width="wrap_content"android:layout_height="57dp"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><Button
                android:id="@+id/bt_page_home"android:layout_width="35dp"android:layout_height="35dp"android:layout_gravity="center_horizontal"android:background="@drawable/home_pressed"android:clickable="false" /><TextView
                android:id="@+id/tv_page_home"android:textColor="#ffd100"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="32dp"android:text="首页" /></FrameLayout><FrameLayout
            android:id="@+id/fl_page_budget"android:layout_width="wrap_content"android:layout_height="57dp"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><Button
                android:id="@+id/bt_page_budget"android:layout_width="35dp"android:layout_height="35dp"android:layout_gravity="center_horizontal"android:background="@drawable/budget"android:clickable="false" /><TextView
                android:textColor="#383838"android:id="@+id/tv_page_budget"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="32dp"android:text="记账" /></FrameLayout><FrameLayout
            android:id="@+id/fl_page_more"android:layout_width="wrap_content"android:layout_height="57dp"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><Button
                android:id="@+id/bt_page_more"android:layout_width="35dp"android:layout_height="35dp"android:layout_gravity="center_horizontal"android:background="@drawable/more"android:clickable="false" /><TextView
                android:id="@+id/tv_page_more"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:layout_marginTop="32dp"android:text="更多" /></FrameLayout></LinearLayout></LinearLayout>

继续回到对应的MainActivity:并加入了按两次回退键退出程序。

package activity;import ...public class MainActivity extends FragmentActivity implements View.OnClickListener {private ViewPager mViewPager;private MyFragmentPagerAdapter mAdapter;private List<Fragment> fragmentList; //保存界面的viewprivate FrameLayout fl_page_home, fl_page_budget, fl_page_more;private LinearLayout ll_taball;private Button bt_page_home, bt_page_budget, bt_page_more;private TextView tv_page_home;private TextView tv_page_budget;private TextView tv_page_more;private TextView tv_top_title;//onkeydown_private static boolean isQuit = false;private Timer timer = new Timer();//onResult的码private static final int addActivityRequestCodeOfPage2 = 0,addActivityRequestCodeOfPage1=1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);StatusBarUtil.setWindowStatusBarColor(this, R.color.colorTitleGray);initViews();setViewPagerEvent();initEvents();initDatas();}@Overrideprotected void onRestart() {super.onRestart();}/*** viewPager切换页面的事件*/private void setViewPagerEvent() {//设置viewpager的page监听换bottom按钮颜色mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {@Overridepublic void onPageSelected(int position) {int currentItem = mViewPager.getCurrentItem();switch (currentItem) {case 0:resetImgAndTextColorAndButton();bt_page_home.setBackgroundResource(R.drawable.home_pressed);tv_page_home.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("首页");bt_add.setVisibility(View.VISIBLE);bt_add.setBackgroundResource(R.drawable.selector_main_top_menu);break;case 1:resetImgAndTextColorAndButton();bt_page_budget.setBackgroundResource(R.drawable.budget_pressed);tv_page_budget.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("记录");bt_add.setVisibility(View.VISIBLE);bt_add.setBackgroundResource(R.drawable.selector_add_button);break;case 2:resetImgAndTextColorAndButton();bt_page_more.setBackgroundResource(R.drawable.more_pressed);tv_page_more.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("更多");bt_add.setVisibility(View.INVISIBLE);break;default:break;}}@Overridepublic void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}@Overridepublic void onPageScrollStateChanged(int state) {}});}/*** 数据初始化*/private void initDatas() {//fragment数据源fragmentList = new ArrayList<Fragment>();fragmentList.add(new Fragment_tab01());fragmentList.add(new Fragment_tab02());fragmentList.add(new Fragment_tab03());mAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragmentList);mViewPager.setAdapter(mAdapter);}/*** 初始化事件*/private void initEvents() {fl_page_home.setOnClickListener(this);fl_page_budget.setOnClickListener(this);fl_page_more.setOnClickListener(this);bt_add.setOnClickListener(this);}/*** 初始化控件*/private void initViews() {mViewPager = (ViewPager) findViewById(R.id.vp_mainvp);//底部的布局fl_page_home = (FrameLayout) findViewById(R.id.fl_page_home);fl_page_budget = (FrameLayout) findViewById(R.id.fl_page_budget);fl_page_more = (FrameLayout) findViewById(R.id.fl_page_more);//底部的按钮bt_page_home = (Button) findViewById(R.id.bt_page_home);bt_page_budget = (Button) findViewById(R.id.bt_page_budget);bt_page_more = (Button) findViewById(R.id.bt_page_more);//按钮对应文字的颜色tv_page_home = (TextView) findViewById(R.id.tv_page_home);tv_page_budget = (TextView) findViewById(R.id.tv_page_budget);tv_page_more = (TextView) findViewById(R.id.tv_page_more);//顶部状态栏文字tv_top_title = (TextView) findViewById(R.id.tv_top_title);ll_taball = (LinearLayout) findViewById(R.id.ll_taball);//记一笔按钮bt_add = (Button) findViewById(R.id.bt_add);bt_add.setVisibility(View.VISIBLE);}/*** 点击下面的布局按钮事件** @param v*/@Overridepublic void onClick(View v) {resetImgAndTextColorAndButton();switch (v.getId()) {/*** 底部导航栏按钮*/case R.id.fl_page_home:mViewPager.setCurrentItem(0);//如果首页 切换首页bt_page_home.setBackgroundResource(R.drawable.home_pressed);//并将按钮颜色点亮tv_page_home.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("首页");bt_add.setVisibility(View.VISIBLE);bt_add.setBackgroundResource(R.drawable.selector_main_top_menu);break;case R.id.fl_page_budget:mViewPager.setCurrentItem(1);bt_page_budget.setBackgroundResource(R.drawable.budget_pressed);tv_page_budget.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("记录");bt_add.setVisibility(View.VISIBLE);bt_add.setBackgroundResource(R.drawable.selector_add_button);break;case R.id.fl_page_more:mViewPager.setCurrentItem(2);bt_page_more.setBackgroundResource(R.drawable.more_pressed);tv_page_more.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("更多");bt_add.setVisibility(View.INVISIBLE);break;default:break;}}/*** 设置所有图片暗色和文字*/private void resetImgAndTextColorAndButton() {bt_page_home.setBackgroundResource(R.drawable.home);bt_page_budget.setBackgroundResource(R.drawable.budget);bt_page_more.setBackgroundResource(R.drawable.more);tv_page_home.setTextColor(Color.rgb(56, 56, 56));tv_page_budget.setTextColor(Color.rgb(56, 56, 56));tv_page_more.setTextColor(Color.rgb(56, 56, 56));}/*** 回退按钮两次退出*/@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {if (isQuit == false) {isQuit = true;ToastUtil.showToast(getApplicationContext(), "请按两次回退键退出", 3000);TimerTask task = null;task = new TimerTask() {@Overridepublic void run() {isQuit = false;}};timer.schedule(task, 2000);} else {finish();System.exit(0);}}return true;}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode == addActivityRequestCodeOfPage2) {mViewPager.setCurrentItem(1);bt_page_budget.setBackgroundResource(R.drawable.budget_pressed);tv_page_budget.setTextColor(Color.rgb(255, 209, 0));}else if (requestCode==addActivityRequestCodeOfPage1){bt_page_home.setBackgroundResource(R.drawable.home_pressed);tv_page_home.setTextColor(Color.rgb(255, 209, 0));}}}

最后加入的onActivityResult是对应如下情况,如果在某个Fragment中对应进去了其他的Activity时,返回以后导航栏是没有之前的显示的,所以如下就要返回原来的显示。

@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode == addActivityRequestCodeOfPage2) {mViewPager.setCurrentItem(1);bt_page_budget.setBackgroundResource(R.drawable.budget_pressed);tv_page_budget.setTextColor(Color.rgb(255, 209, 0));}else if (requestCode==addActivityRequestCodeOfPage1){bt_page_home.setBackgroundResource(R.drawable.home_pressed);tv_page_home.setTextColor(Color.rgb(255, 209, 0));}}

第三步,顶部右上角菜单。

之前导入顶部栏的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="43dp"android:background="@color/colorTitleGray"><TextView
        android:id="@+id/tv_top_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:layout_gravity="center"android:text="首页"android:textColor="@color/ccd1d9white"android:textSize="20sp" /><Button
        android:layout_marginRight="8dp"android:layout_width="28dp"android:layout_height="28dp"android:background="@drawable/selector_main_top_menu"android:layout_centerVertical="true"android:layout_alignParentEnd="true"android:id="@+id/bt_add" /></RelativeLayout>

对应菜单我们使用PopupWindow 。

package views;import .../*** Created by Chase on 2017/2/23.*/public class TopPopWindow extends PopupWindow {private View mView;private LinearLayout ll_popmenu_record,ll_popmenu_book,ll_popmenu_search;public  TopPopWindow(Activity paramActivity, View.OnClickListener paramOnClickListener,int paramInt1, int paramInt2){mView = LayoutInflater.from(paramActivity).inflate(R.layout.popwindow_topright, null);ll_popmenu_record = (LinearLayout) mView.findViewById(R.id.ll_popmenu_record);ll_popmenu_book = (LinearLayout) mView.findViewById(R.id.ll_popmenu_book);ll_popmenu_search = (LinearLayout) mView.findViewById(R.id.ll_popmenu_search);if (paramOnClickListener != null){//设置点击监听ll_popmenu_record.setOnClickListener(paramOnClickListener);ll_popmenu_book.setOnClickListener(paramOnClickListener);ll_popmenu_search.setOnClickListener(paramOnClickListener);setContentView(mView);//设置宽度setWidth(paramInt1);//设置高度setHeight(paramInt2);//设置显示隐藏动画setAnimationStyle(R.style.AnimTools);//设置背景透明setBackgroundDrawable(new ColorDrawable(0));}}}

编写PopupWindow 的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="match_parent"android:layout_marginRight="5dp"android:layout_marginTop="20dp"android:background="@drawable/popmenu"android:orientation="vertical"><LinearLayout
        android:id="@+id/ll_popmenu_record"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginBottom="8dp"android:paddingLeft="10dp"android:gravity="center_vertical"android:orientation="horizontal"><ImageView
            android:layout_width="25dp"android:layout_height="25dp"android:src="@mipmap/add" /><TextView
            android:textColor="#aab2bd"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:gravity="center_vertical"android:text="记一笔"android:textSize="20sp" /></LinearLayout><TextView
        android:layout_width="match_parent"android:layout_height="0.7dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:background="#aab2bd" /><LinearLayout
        android:id="@+id/ll_popmenu_book"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginTop="8dp"android:gravity="center_vertical"android:orientation="horizontal"android:layout_marginBottom="8dp"><ImageView
            android:layout_width="25dp"android:layout_height="25dp"android:src="@mipmap/book" /><TextView
            android:textColor="#aab2bd"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:gravity="center_vertical"android:text="账本切换"android:textSize="20sp" /></LinearLayout><TextView
        android:layout_width="match_parent"android:layout_height="0.7dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:background="#aab2bd" /><LinearLayout
        android:id="@+id/ll_popmenu_search"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginTop="8dp"android:gravity="center_vertical"android:orientation="horizontal"><ImageView
            android:layout_width="25dp"android:layout_height="25dp"android:src="@mipmap/search" /><TextView
            android:textColor="#aab2bd"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:gravity="center_vertical"android:text="搜索账本"android:textSize="20sp" /></LinearLayout>
</LinearLayout>

回到MainActivity:

package activity;import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;import com.chase.cn.money_of_my.R;import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;import utils.MyFragmentPagerAdapter;
import utils.StatusBarUtil;
import utils.ToastUtil;
import views.TopPopWindow;public class MainActivity extends FragmentActivity implements View.OnClickListener {private ViewPager mViewPager;private MyFragmentPagerAdapter mAdapter;private List<Fragment> fragmentList; //保存界面的viewprivate FrameLayout fl_page_home, fl_page_budget, fl_page_more;private LinearLayout ll_taball;private Button bt_page_home, bt_page_budget, bt_page_more;private Button bt_add;private TextView tv_page_home;private TextView tv_page_budget;private TextView tv_page_more;private TextView tv_top_title;//onkeydown_private static boolean isQuit = false;private Timer timer = new Timer();//onResult的码private static final int addActivityRequestCodeOfPage2 = 0,addActivityRequestCodeOfPage1=1;private TopPopWindow topPopWindow;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);StatusBarUtil.setWindowStatusBarColor(this, R.color.colorTitleGray);initViews();setViewPagerEvent();initEvents();initDatas();}@Overrideprotected void onRestart() {super.onRestart();}/*** viewPager切换页面的事件*/private void setViewPagerEvent() {//设置viewpager的page监听换bottom按钮颜色mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {@Overridepublic void onPageSelected(int position) {int currentItem = mViewPager.getCurrentItem();switch (currentItem) {case 0:resetImgAndTextColorAndButton();bt_page_home.setBackgroundResource(R.drawable.home_pressed);tv_page_home.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("首页");bt_add.setVisibility(View.VISIBLE);bt_add.setBackgroundResource(R.drawable.selector_main_top_menu);break;case 1:resetImgAndTextColorAndButton();bt_page_budget.setBackgroundResource(R.drawable.budget_pressed);tv_page_budget.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("记录");bt_add.setVisibility(View.VISIBLE);bt_add.setBackgroundResource(R.drawable.selector_add_button);break;case 2:resetImgAndTextColorAndButton();bt_page_more.setBackgroundResource(R.drawable.more_pressed);tv_page_more.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("更多");bt_add.setVisibility(View.INVISIBLE);break;default:break;}}@Overridepublic void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}@Overridepublic void onPageScrollStateChanged(int state) {}});}/*** 数据初始化*/private void initDatas() {//fragment数据源fragmentList = new ArrayList<Fragment>();fragmentList.add(new Fragment_tab01());fragmentList.add(new Fragment_tab02());fragmentList.add(new Fragment_tab03());mAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragmentList);mViewPager.setAdapter(mAdapter);}/*** 初始化事件*/private void initEvents() {fl_page_home.setOnClickListener(this);fl_page_budget.setOnClickListener(this);fl_page_more.setOnClickListener(this);bt_add.setOnClickListener(this);}/*** 初始化控件*/private void initViews() {mViewPager = (ViewPager) findViewById(R.id.vp_mainvp);//底部的布局fl_page_home = (FrameLayout) findViewById(R.id.fl_page_home);fl_page_budget = (FrameLayout) findViewById(R.id.fl_page_budget);fl_page_more = (FrameLayout) findViewById(R.id.fl_page_more);//底部的按钮bt_page_home = (Button) findViewById(R.id.bt_page_home);bt_page_budget = (Button) findViewById(R.id.bt_page_budget);bt_page_more = (Button) findViewById(R.id.bt_page_more);//按钮对应文字的颜色tv_page_home = (TextView) findViewById(R.id.tv_page_home);tv_page_budget = (TextView) findViewById(R.id.tv_page_budget);tv_page_more = (TextView) findViewById(R.id.tv_page_more);//顶部状态栏文字tv_top_title = (TextView) findViewById(R.id.tv_top_title);ll_taball = (LinearLayout) findViewById(R.id.ll_taball);//记一笔按钮bt_add = (Button) findViewById(R.id.bt_add);bt_add.setVisibility(View.VISIBLE);}/*** 点击下面的布局按钮事件** @param v*/@Overridepublic void onClick(View v) {resetImgAndTextColorAndButton();switch (v.getId()) {/*** 底部导航栏按钮*/case R.id.fl_page_home:mViewPager.setCurrentItem(0);//如果首页 切换首页bt_page_home.setBackgroundResource(R.drawable.home_pressed);//并将按钮颜色点亮tv_page_home.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("首页");bt_add.setVisibility(View.VISIBLE);bt_add.setBackgroundResource(R.drawable.selector_main_top_menu);break;case R.id.fl_page_budget:mViewPager.setCurrentItem(1);bt_page_budget.setBackgroundResource(R.drawable.budget_pressed);tv_page_budget.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("记录");bt_add.setVisibility(View.VISIBLE);bt_add.setBackgroundResource(R.drawable.selector_add_button);break;case R.id.fl_page_more:mViewPager.setCurrentItem(2);bt_page_more.setBackgroundResource(R.drawable.more_pressed);tv_page_more.setTextColor(Color.rgb(255, 209, 0));tv_top_title.setText("更多");bt_add.setVisibility(View.INVISIBLE);break;/*** 记一笔按钮*/case R.id.bt_add:if (mViewPager.getCurrentItem() == 1) {Intent intent_add_activity = new Intent(getApplicationContext(), AddRecorderActivity.class);startActivityForResult(intent_add_activity, addActivityRequestCodeOfPage2);} else {bt_page_home.setBackgroundResource(R.drawable.home_pressed);//并将按钮颜色点亮tv_page_home.setTextColor(Color.rgb(255, 209, 0));showTopRightPopMenu();}break;/*** popwindow引入的方法的onclick的listener引入到this* popwindow的点击事件*/case R.id.ll_popmenu_record:Intent intent_add_activity = new Intent(getApplicationContext(), AddRecorderActivity.class);startActivityForResult(intent_add_activity,addActivityRequestCodeOfPage1);topPopWindow.dismiss();break;case R.id.ll_popmenu_book:ToastUtil.showSucceccToast(getApplicationContext(), "success12", 3000);break;case R.id.ll_popmenu_search:ToastUtil.showSucceccToast(getApplicationContext(), "success13", 3000);break;default:break;}}/*** 显示右上角popup菜单*/private void showTopRightPopMenu() {if (topPopWindow == null) {//(activity,onclicklistener,width,height)topPopWindow = new TopPopWindow(MainActivity.this, this, 360, 290);//监听窗口的焦点事件,点击窗口外面则取消显示topPopWindow.getContentView().setOnFocusChangeListener(new View.OnFocusChangeListener() {@Overridepublic void onFocusChange(View v, boolean hasFocus) {if (!hasFocus) {topPopWindow.dismiss();}}});}//设置默认获取焦点topPopWindow.setFocusable(true);//以某个控件的x和y的偏移量位置开始显示窗口topPopWindow.showAsDropDown(bt_add, 0, 0);//如果窗口存在,则更新topPopWindow.update();}/*** 设置所有图片暗色和文字*/private void resetImgAndTextColorAndButton() {bt_page_home.setBackgroundResource(R.drawable.home);bt_page_budget.setBackgroundResource(R.drawable.budget);bt_page_more.setBackgroundResource(R.drawable.more);tv_page_home.setTextColor(Color.rgb(56, 56, 56));tv_page_budget.setTextColor(Color.rgb(56, 56, 56));tv_page_more.setTextColor(Color.rgb(56, 56, 56));}/*** 回退按钮两次退出*/@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {if (isQuit == false) {isQuit = true;ToastUtil.showToast(getApplicationContext(), "请按两次回退键退出", 3000);TimerTask task = null;task = new TimerTask() {@Overridepublic void run() {isQuit = false;}};timer.schedule(task, 2000);} else {finish();System.exit(0);}}return true;}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode == addActivityRequestCodeOfPage2) {mViewPager.setCurrentItem(1);bt_page_budget.setBackgroundResource(R.drawable.budget_pressed);tv_page_budget.setTextColor(Color.rgb(255, 209, 0));}else if (requestCode==addActivityRequestCodeOfPage1){bt_page_home.setBackgroundResource(R.drawable.home_pressed);tv_page_home.setTextColor(Color.rgb(255, 209, 0));}}
}

右上角的按钮还添加了功能,在不同的Fragment中,它的功能不同。

以上就算安卓模仿微信界面的步骤了。

安卓仿微信界面,导航,右上角菜单栏相关推荐

  1. 安卓开发— —仿微信界面(一)

    目录 一.项目内容 二.代码实现 1.项目结构 2.头部代码 3.底部代码 4.四个内容界面 5.窗体总布局 6.MainActivity实现点击图标与页面的互动 三.运行效果 四.总结 一.项目内容 ...

  2. uniapp可以封装组件嘛_uniapp聊天App实例|vue+uniapp仿微信界面|红包|朋友圈

    一.功能阐述 今天给大家分享的是基于UniApp+Vue+Vuex+swiper+uniPop等技术开发的仿微信原生App聊天室|仿微信聊天界面实例项目uniapp-chatroom,实现了发送图文消 ...

  3. Android 二维码扫描(仿微信界面),根据Google zxing

    Android 二维码扫描(仿微信界面),根据Google zxing Android项目开发中经常会用到二维码扫描,例如登陆.支付等谷歌方面已经有了一个开源库(地址: https://github. ...

  4. imchat视频聊天室 linux,基于Nuxt+Vant聊天模板|nuxt.js仿微信界面|红包|朋友圈

    项目说明 > [NuxtIMChat项目]是基于vue.js+nuxt.js+vuex+webpack+vant-ui开发的仿微信聊天实例.实现了消息发送.图片/视频预览.下拉刷新/长按弹窗.朋 ...

  5. 是男人就下100层【第一层】——高仿微信界面(5)

    前面< 是男人就下100层[第一层]--高仿微信界面(4)>中我们已经完成了基本的引导界面和登录界面,这一篇中我们来看看登录后的主界面的布局和内容,来一步一步的完成该界面. 我们先来看看主 ...

  6. 是男人就下100层【第一层】——高仿微信界面(4)

    上一篇<是男人就下100层[第一层]--高仿微信界面(3)>中我们完成了登录,这一篇看完成登录后的一个短暂加载和引导界面. 加载界面: <RelativeLayout xmlns:a ...

  7. WPF仿微信界面发送消息简易版

    WPF仿微信界面发送消息简易版 参考别的博主的例子用WPF MVVM框架来仿了一个微信聊天界面,做了个发送消息简易功能,下面一起来看看吧! 以下为View视图布局代码,消息对话框的样式直接在这里定义了 ...

  8. 【Android 仿微信通讯录 导航分组列表-上】使用ItemDecoration为RecyclerView打造带悬停头部的分组列表

    *本篇文章已授权微信公众号 guolin_blog (郭霖)独家发布 转载请标明出处: http://blog.csdn.net/zxt0601/article/details/52355199 本文 ...

  9. QT_QML_仿微信界面(实战)

    QT_QML_仿微信界面(实战) 效果如下: 代码获取地址: 链接:https://pan.baidu.com/s/1wmDqpe94HnY_OPjSou5xBg 提取码:xmkt

最新文章

  1. iOS开发-简单工厂模式
  2. Android 聊天软件客户端
  3. 10、游标(Cursor)的定义及使用
  4. Nacos(九)之Dubbo 融合 Nacos 成为注册中心
  5. 浅析常用软件架构中的一定要理解的三种架构模型
  6. JeecgBoot轻松解决ERP项目复杂布局需求,JVXETable高性能行表格效果和项目案例
  7. 沈航C语言上机实验题答案,大学大一c语言程序设计实验室上机题全部代码答案(实验报告).doc...
  8. mybatis异常:Could not find result map ......... 问题分析及解决
  9. 计算机画布模式,商业模式画布基础知识
  10. 最新高德地图使用——申请key、显示地图
  11. Python+Selenium实现网页截图
  12. 迅捷路由器造成计算机无法上网,迅捷无线路由器设置好却不能上网
  13. 一文读懂交叉熵和最大似然的关系及在人脸识别中的应用
  14. Jetbrains系列产品
  15. 奋斗吧,程序员——第五章 行路难!行路难!多歧路,今安在
  16. bootstrap 表单提交验证
  17. 电源模块可以并联使用吗?!
  18. android乐视视频直播技术,乐视网进军android平台开发领域
  19. 关于使用阿里云服务调用识别身份证图片、营业执照的信息抓取接口的简单实现
  20. 安卓程序 静默 截屏工具_安卓定制系统开放性对比测试:到底谁最自由?

热门文章

  1. 计算机图形学(三)_图元的属性_4_线的属性_1_线宽
  2. C语言的运算符及优先级
  3. 基于python的马尔科夫链在股价预测中的应用(基于Tushare)
  4. openfire的入门学习
  5. Python数据收集入门
  6. WPF基础系列二:控件简介
  7. 选择电子商务平台:Shopify与WooCommerce
  8. Cesium之鼠标事件绑定和移除
  9. uiautomator2+python3,实现手机解锁,以及软件登录
  10. [XJTU计算机网络安全与管理]——第十三讲 攻击与病毒