android按钮的实现页面跳转页面,android的页面四个按钮实现跳转

当前位置:编程学习 > wap >>

android的页面四个按钮实现跳转

求助此页面加载不出来,求大神解疑惑啊

2f5348681799f5f9ef1c3ee115f13974.gif

import android.app.Activity;

import android.app.TabActivity;

import android.content.Intent;

import android.graphics.Color;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.TabHost;

import android.widget.TabHost.TabSpec;

import android.widget.TextView;

public class MineActivity extends TabActivity implements OnClickListener{

public static String TAB_Love= "@string/love";

public static String TAB_Share= "@string/share";

public static String TAB_Follow = "@string/follow";

public static String TAB_Fans = "@string/fans";

public static TabHost mTabHost;

public Button Btn1, Btn2, Btn3,Btn4;

TextView Txt1, Txt2,Txt3,Txt4,Txt5;

private Animation left_in, left_out;

private Animation right_in, right_out;

Intent LoveItent, ShareIntent, FollowIntent,FansIntent;

int mCurTabId = R.id.btn1;

static final int COLOR1 = Color.parseColor("#000000");

static final int COLOR2 = Color.parseColor("#ffffff");

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.mine);

prepareAnim();

prepareIntent();

setupIntent();

prepareView();

}

private void prepareAnim() {

left_in = AnimationUtils.loadAnimation(this, R.anim.left_in);

left_out = AnimationUtils.loadAnimation(this, R.anim.left_out);

right_in = AnimationUtils.loadAnimation(this, R.anim.right_in);

right_out = AnimationUtils.loadAnimation(this, R.anim.right_out);

}

// prepareIntent()喜欢Button,分享Button,粉丝Button,关注Button的触发页面的改变

private void prepareView() {

Btn1 = (Button) findViewById(R.id.btn1);

Btn2 = (Button) findViewById(R.id.btn2);

Btn3 = (Button) findViewById(R.id.btn3);

Btn4 = (Button) findViewById(R.id.btn4);

findViewById(R.id.channel1).setOnClickListener(this);

findViewById(R.id.channel2).setOnClickListener(this);

findViewById(R.id.channel3).setOnClickListener(this);

findViewById(R.id.channel4).setOnClickListener(this);

findViewById(R.id.channel5).setOnClickListener(this);

Txt1 = (TextView) findViewById(R.id.txt1);

Txt2 = (TextView) findViewById(R.id.txt2);

Txt3 = (TextView) findViewById(R.id.txt3);

Txt4 = (TextView) findViewById(R.id.txt4);

Txt5 = (TextView) findViewById(R.id.txt5);

}

// prepareIntent()喜欢Button,分享Button,粉丝Button,关注Button的触发跳转页面事件

private void prepareIntent() {

LoveItent= new Intent(this, MineLoveActivity.class);

ShareIntent= new Intent(this, MineShareActivity.class);

FollowIntent= new Intent(this, MineFollowActivity.class);

FansIntent  = new Intent(this,MineFansActivity.class);

}

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

// TODO Auto-generated method stub

if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {

Btn1.performClick();

return true;

}

return super.onKeyDown(keyCode, event);

}

private void setupIntent() {

mTabHost = getTabHost();

mTabHost.addTab(buildTabSpec(TAB_Love, R.string.love, LoveItent));

mTabHost.addTab(buildTabSpec(TAB_Share,R.string.share,ShareIntent));

mTabHost.addTab(buildTabSpec(TAB_Follow, R.string.follow,FollowIntent));

mTabHost.addTab(buildTabSpec(TAB_Fans,R.string.fans, FansIntent));

}

private TabSpec buildTabSpec(String tAB_Fans2, int fans, int icon4n,

Intent fansIntent2) {

// TODO Auto-generated method stub

return null;

}

private TabHost.TabSpec buildTabSpec(String tag, int resLabel, final Intent content) {

return mTabHost

.newTabSpec(tag)

.setIndicator(getString(resLabel))

.setContent(content);

}

public static void setCurrentTabByTag(String tab) {

mTabHost.setCurrentTabByTag(tab);

}

//四个button的点击事件

@Override

public void onClick(View v) {

if (mCurTabId == v.getId()) {

return;

}

Btn1.setTextColor(COLOR1);

Btn2.setTextColor(COLOR1);

Btn3.setTextColor(COLOR1);

Btn4.setTextColor(COLOR1);

Txt1.setTextColor(COLOR1);

Txt2.setTextColor(COLOR1);

Txt3.setTextColor(COLOR1);

Txt4.setTextColor(COLOR1);

Txt5.setTextColor(COLOR1);

int checkedId = v.getId();

final boolean o;

if (mCurTabId 

o = true;

else

o = false;

if (o)

mTabHost.getCurrentView().startAnimation(left_out);

else

mTabHost.getCurrentView().startAnimation(right_out);

//实现点击某个快,对应的button和人数由黑色变成白色

switch (checkedId) {

case R.id.channel1:

mTabHost.setCurrentTabByTag(TAB_Love);

Btn1.setTextColor(COLOR2);

Txt2.setTextColor(COLOR2);

break;

case R.id.channel2:

mTabHost.setCurrentTabByTag(TAB_Share);

Btn2.setTextColor(COLOR2);

Txt3.setTextColor(COLOR2);

break;

case R.id.channel3:

mTabHost.setCurrentTabByTag(TAB_Follow);

Btn3.setTextColor(COLOR2);

Txt4.setTextColor(COLOR2);

break;

case R.id.channel4:

mTabHost.setCurrentTabByTag(TAB_Fans);

Btn4.setTextColor(COLOR2);

Txt5.setTextColor(COLOR2);

break;

default:

break;

}

if (o)

mTabHost.getCurrentView().startAnimation(left_in);

else

mTabHost.getCurrentView().startAnimation(right_in);

mCurTabId = checkedId;

}

}

android的页面四个按钮实现跳转

android

--------------------编程问答--------------------

四个Button的按键响应时间没绑定。

在prepareView()方法里加上:

Btn1.setOnClickListener(this);

Btn2.setOnClickListener(this);

Btn3.setOnClickListener(this);

Btn4.setOnClickListener(this);

在onClick()方法里加上对应每个按钮的响应:startActivity(intent),传入对应的intent。

--------------------编程问答--------------------

楼上正解。。。。。。。。。。

--------------------编程问答--------------------

太感谢了,我解决了这个问题了,

mTabHost.addTab(mTabHost.newTabSpec("love").setIndicator("",getResources ().getDrawable(R.id.Btn1)).setContent(new Intent(this, LoveActivity.class)));

我这么写的话有问题吗/

补充:移动开发 , Android

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值