主页
用的是Fragment 这样的好处是可以独立编辑独立的页
package com.example.weixin_jiemian;
import java.util.ArrayList;
import java.util.List;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.LinearLayout;
public class MainActivity extends FragmentActivity implements OnClickListener {
private LinearLayout mTabweixin;
private LinearLayout mTabpengy;
private LinearLayout mTabtongxun;
private LinearLayout mTabshezhi;
private ImageButton mweixinButton;
private ImageButton mpengyButton;
private ImageButton mtongxunluButton;
private ImageButton mshezhiButton;
private ViewPager mviewPager;
private FragmentPagerAdapter mAdapter;
private List shuju;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.zhuyao);
intview1();
fangfa2();
qiehuantupian(0);
}
private void fangfa2() {
mTabweixin.setOnClickListener(this);
mTabpengy.setOnClickListener(this);
mTabtongxun.setOnClickListener(this);
mTabshezhi.setOnClickListener(this);
}
private void intview1() {
mviewPager = (ViewPager) findViewById(R.id.id_viewpager);
mTabweixin = (LinearLayout) findViewById(R.id.id_buju_weixin);
mTabpengy = (LinearLayout) findViewById(R.id.id_buju_pengyou);
mTabtongxun = (LinearLayout) findViewById(R.id.id_buju_tongxunlu);
mTabshezhi = (LinearLayout) findViewById(R.id.id_buju_shezhi);
mweixinButton = (ImageButton) findViewById(R.id.id_tab_weixin_tupian);
mpengyButton = (ImageButton) findViewById(R.id.id_tab_pengyou_tupian);
mtongxunluButton = (ImageButton) findViewById(R.id.id_tab_tongxunlu_tupian);
mshezhiButton = (ImageButton) findViewById(R.id.id_tab_shezhi_tupian);
shuju = new ArrayList();
Fragment tb01 = new weixin();
Fragment tb02 = new pengy();
Fragment tb03 = new tongxunlu();
Fragment tb04 = new shezhi();
shuju.add(tb01);
shuju.add(tb02);
shuju.add(tb03);
shuju.add(tb04);
mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
// TODO 自动生成的方法存根
return shuju.size();
}
@Override
public Fragment getItem(int arg0) {
// TODO 自动生成的方法存根
return shuju.get(arg0);
}
};
mviewPager.setAdapter(mAdapter);
}
public void qiehuantupian(int i) { // 切换图片亮度和绑定页数
mviewPager.setCurrentItem(i);
mviewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
int currenItem= mviewPager.getCurrentItem();
setTab(currenItem);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO 自动生成的方法存根
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO 自动生成的方法存根
}
});
}
private void setTab(int i) {
huantubian();
switch (i) {
case 0:
mweixinButton.setImageResource(R.drawable.tab_weixin_pressed);
break;
case 1:
mpengyButton.setImageResource(R.drawable.tab_find_frd_pressed);
break;
case 2:
mtongxunluButton.setImageResource(R.drawable.tab_address_pressed);
break;
case 3:
mshezhiButton.setImageResource(R.drawable.tab_settings_pressed);
break;
default:
break;
}
}
@Override
public void onClick(View arg0) {
switch (arg0.getId()) {
case R.id.id_buju_weixin:
qiehuantupian(0);
break;
case R.id.id_buju_pengyou:
qiehuantupian(1);
break;
case R.id.id_buju_tongxunlu:
qiehuantupian(2);
break;
case R.id.id_buju_shezhi:
qiehuantupian(3);
break;
default:
break;
}
}
private void huantubian() { // 切换图片
mweixinButton.setImageResource(R.drawable.tab_weixin_normal);
mpengyButton.setImageResource(R.drawable.tab_find_frd_normal);
mtongxunluButton.setImageResource(R.drawable.tab_address_normal);
mshezhiButton.setImageResource(R.drawable.tab_settings_normal);
}
}
朋友···············
package com.example.weixin_jiemian;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class pengy extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO 自动生成的方法存根
return inflater.inflate(R.layout.yemian2, container, false);
}
}
设置
package com.example.weixin_jiemian;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class shezhi extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO 自动生成的方法存根
return inflater.inflate(R.layout.yemian4, container, false);
}
}
通讯录
package com.example.weixin_jiemian;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class tongxunlu extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO 自动生成的方法存根
return inflater.inflate(R.layout.yemian3, container, false);
}
}
微信
package com.example.weixin_jiemian;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class weixin extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO 自动生成的方法存根
return inflater.inflate(R.layout.yemian1, container, false);
}
}
打开App,阅读手记