




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】Android如何实现仿微信界面的导航以及右上角菜单栏效果
这篇文章主要介绍了Android如何实现仿微信界面的导航以及右上角菜单栏效果,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让在下带着大家一起了解一下。第一步,界面。界面的思路是利用ViewPager+Fragment实现,所以activity_main.xml中添加一个ViewPager。顶部和底部include的顶部栏和底部栏后面再说。MainActivity的界面activity_main.xml:<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="/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
.money_of_my.R;
/**
*
Created
by
Chase
on
2017/2/6.
*/
public
class
Fragment_tab01
extends
Fragment
{
@Override
public
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="/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
@Override
protected
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;
}
@Override
public
CharSequence
getPageTitle(int
position)
{
return
tabList.get(position);
}
@Override
public
Fragment
getItem(int
position)
{
return
fragList.get(position);
}
@Override
public
int
getCount()
{
return
fragList.size();
}
}现在三个Fragment已经添加到了MainActivity中,滑动ViewPager切换Fragment,同时底部的导航栏也会切换,在为ViewPager添加监听以前,先说说底部导航栏。第二步,底部导航。这个的切换其实就是切换准备好的png图片和改变文字的颜色。下面是刚才导入的底部导航栏xml文件:<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="/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;
//保存界面的view
private
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;
@Override
protected
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StatusBarUtil.setWindowStatusBarColor(this,
R.color.colorTitleGray);
initViews();
setViewPagerEvent();
initEvents();
initDatas();
}
@Override
protected
void
onRestart()
{
super.onRestart();
}
/**
*
viewPager切换页面的事件
*/
private
void
setViewPagerEvent()
{
//设置viewpager的page监听换bottom按钮颜色
mViewPager.setOnPageChangeListener(new
ViewPager.OnPageChangeListener()
{
@Override
public
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;
}
}
@Override
public
void
onPageScrolled(int
position,
float
positionOffset,
int
positionOffsetPixels)
{
}
@Override
public
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
*/
@Override
public
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));
}
/**
*
回退按钮两次退出
*/
@Override
public
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()
{
@Override
public
void
run()
{
isQuit
=
false;
}
};
timer.schedule(task,
2000);
}
else
{
finish();
System.exit(0);
}
}
return
true;
}
@Override
protected
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时,返回以后导航栏是没有之前的显示的,所以如下就要返回原来的显示。@Override
protected
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="/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="/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
.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;
//保存界面的view
private
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;
@Override
protected
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StatusBarUtil.setWindowStatusBarColor(this,
R.color.colorTitleGray);
initViews();
setViewPagerEvent();
initEvents();
initDatas();
}
@Override
protected
void
onRestart()
{
super.onRestart();
}
/**
*
viewPager切换页面的事件
*/
private
void
setViewPagerEvent()
{
//设置viewpager的page监听换bottom按钮颜色
mViewPager.setOnPageChangeListener(new
ViewPager.OnPageChangeListener()
{
@Override
public
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;
}
}
@Override
public
void
onPageScrolled(int
position,
float
positionOffset,
int
positionOffsetPixels)
{
}
@Override
public
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
*/
@Override
public
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.setText
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 单位宪法宣传课件
- 卓越绩效管理课件教学
- 卒中患者体位管理课件
- 广州执信入学数学试卷
- 华为客户管理课件
- 海淀区中考数学试卷
- 衡阳小学6年级数学试卷
- 广益中学数学试卷
- 《网络综合布线》教案 项目1实训任务 制作网络跳线和端接网络模块
- 2025届重庆实验中学物理高二第二学期期末联考模拟试题含解析
- 河南省郑州市2025年高中毕业年级第三次质量预测英语试题(含答案无听力原文及音频)
- 语音主播经纪合同协议
- 2025-2030成都市医疗机构行业市场发展分析及发展前景与投资研究报告
- 新版器械GCP培训课件
- 《小学生网络安全教育》课件
- 2025年高级评茶员技能鉴定理论考试题库浓缩500题-含答案
- 天翼云从业者题库练习测试题附答案
- 民丰县瑞安矿业投资有限公司民丰县卧龙岗年处理30万吨锑矿选厂及尾矿库建设项目报告书
- 山东济宁历年中考作文题(2004-2024)
- 心脏骤停后高质量目标温度管理专家共识2024
- 合同债权转让及违约金协议
评论
0/150
提交评论