android+通过菜单跳转页面,【风马一族_Android】通过菜单的点击,跳转到不同界面...

---恢复内容开始---

布局的代码:activity_main.xml

1 <?xml version="1.0" encoding="utf-8"?>

2

3 xmlns:tools="http://schemas.android.com/tools"

4 android:layout_width="match_parent"

5 android:layout_height="match_parent"

6 tools:context="com.sowsceo.sms.MainActivity">

7

8

10 android:layout_width="match_parent"

11 android:layout_height="match_parent">

12

13

15 android:layout_height="match_parent"

16 android:orientation="vertical">

17

18

20 android:layout_width="match_parent"

21 android:layout_height="wrap_content">

22

23

25 android:layout_width="match_parent"

26 android:layout_height="match_parent">

27

28

29

逻辑代码 :MainActivity.java

1 importandroid.app.TabActivity;2 importandroid.content.Intent;3 importandroid.support.v7.app.AppCompatActivity;4 importandroid.os.Bundle;5 importandroid.view.View;6 importandroid.widget.TabHost;7

8 public class MainActivity extendsTabActivity {9

10 privateTabHost mTabHos;11

12 @Override13 protected voidonCreate(Bundle savedInstanceState) {14 super.onCreate(savedInstanceState);15 setContentView(R.layout.activity_main);16

17 initTabHost();18 }19

20 /**

21 * 初始化tabHost22 */

23 private voidinitTabHost() {24 mTabHos =(TabHost) findViewById(android.R.id.tabhost);25

26 addTabSpec("conversation","会话",R.drawable.tab_conversation,new Intent(this,ConversationUI.class));27 addTabSpec("folder","文件夹",R.drawable.tab_folder,new Intent(this,FolderUI.class));28 addTabSpec("group","群组",R.drawable.tab_group,new Intent(this,GroupUI.class));29

30 }31

32 /**

33 * 添加一个页签34 *@paramtag 标记35 *@paramlabel 标题36 *@paramicon 图标37 *@paramintent 指向的activity38 */

39 private void addTabSpec(String tag,String label,inticon,Intent intent){40 TabHost.TabSpec newTabSpec =mTabHos.newTabSpec(tag);41

42 newTabSpec.setIndicator(label,getResources().getDrawable(icon));43 //设置页签的标题与图标

44

45 newTabSpec.setContent(intent);46 //设置页签指向的显示内容问activity

47

48 mTabHos.addTab(newTabSpec);49 //添加页签

50 }51

52 }

------------------------------

三个菜单的布局与代码

------------------------------

会话布局:activity_conversation_ui.xml

1 <?xml version="1.0" encoding="utf-8"?>

2

3 xmlns:tools="http://schemas.android.com/tools"

4 android:layout_width="match_parent"

5 android:layout_height="match_parent"

6 android:paddingBottom="@dimen/activity_vertical_margin"

7 android:paddingLeft="@dimen/activity_horizontal_margin"

8 android:paddingRight="@dimen/activity_horizontal_margin"

9 android:paddingTop="@dimen/activity_vertical_margin"

10 tools:context="com.sowsceo.sms.ConversationUI">

11

12

14 android:layout_height="match_parent"

15 android:text="会话"

16 android:textSize="50sp"/>

17

逻辑代码:ConversationUI.java

1 importandroid.app.Activity;2 importandroid.support.v7.app.AppCompatActivity;3 importandroid.os.Bundle;4

5 /**

6 * 会话7 */

8 public class ConversationUI extendsActivity {9

10 @Override11 protected voidonCreate(Bundle savedInstanceState) {12 super.onCreate(savedInstanceState);13 setContentView(R.layout.activity_conversation_ui);14 }15 }

-------------------------------------------

布局代码:activity_folder_ui.xml

逻辑代码:FolderUI.java

1 importandroid.app.Activity;2 importandroid.support.v7.app.AppCompatActivity;3 importandroid.os.Bundle;4

5 /**

6 *7 * 创建者:风马一族8 * 时间: 2016/8/9 19:069 * 说明:文件夹10 */

11

12 public class FolderUI extendsActivity {13

14 @Override15 protected voidonCreate(Bundle savedInstanceState) {16 super.onCreate(savedInstanceState);17 setContentView(R.layout.activity_folder_ui);18 }19 }

----------------------------------

布局代码:activity_group_ui.xml

---恢复内容结束---

原文:http://www.cnblogs.com/sows/p/5755274.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值