风马一族_Android通过菜单的点击,跳转到不同界面

一身转战三千里,一剑曾百万师。这篇文章主要讲述风马一族_Android通过菜单的点击,跳转到不同界面相关的知识,希望能为你提供帮助。
---恢复内容开始---
布局的代码:activity_main.xml

1 < ?xml version="1.0" encoding="utf-8"?> 2 < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3xmlns:tools="http://schemas.android.com/tools" 4android:layout_width="match_parent" 5android:layout_height="match_parent" 6tools:context="com.sowsceo.sms.MainActivity"> 7 8< TabHost 9android:id="@android:id/tabhost" 10android:layout_width="match_parent" 11android:layout_height="match_parent"> 12 13< LinearLayout 14android:layout_width="match_parent" 15android:layout_height="match_parent" 16android:orientation="vertical"> 17 18< TabWidget 19android:id="@android:id/tabs" 20android:layout_width="match_parent" 21android:layout_height="wrap_content"> < /TabWidget> 22 23< FrameLayout 24android:id="@android:id/tabcontent" 25android:layout_width="match_parent" 26android:layout_height="match_parent"> < /FrameLayout> 27< /LinearLayout> 28< /TabHost> 29 < /RelativeLayout>

  逻辑代码 :MainActivity.java
1 import android.app.TabActivity; 2 import android.content.Intent; 3 import android.support.v7.app.AppCompatActivity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.widget.TabHost; 7 8 public class MainActivity extends TabActivity { 9 10private TabHost mTabHos; 11 12@Override 13protected void onCreate(Bundle savedInstanceState) { 14super.onCreate(savedInstanceState); 15setContentView(R.layout.activity_main); 16 17initTabHost(); 18} 19 20/** 21* 初始化tabHost 22*/ 23private void initTabHost() { 24mTabHos = (TabHost) findViewById(android.R.id.tabhost); 25 26addTabSpec("conversation","会话",R.drawable.tab_conversation,new Intent(this,ConversationUI.class)); 27addTabSpec("folder","文件夹",R.drawable.tab_folder,new Intent(this,FolderUI.class)); 28addTabSpec("group","群组",R.drawable.tab_group,new Intent(this,GroupUI.class)); 29 30} 31 32/** 33* 添加一个页签 34* @param tag标记 35* @param label 标题 36* @param icon 图标 37* @param intent 指向的activity 38*/ 39private void addTabSpec(String tag,String label,int icon,Intent intent){ 40TabHost.TabSpec newTabSpec = mTabHos.newTabSpec(tag); 41 42newTabSpec.setIndicator(label,getResources().getDrawable(icon)); 43//设置页签的标题与图标 44 45newTabSpec.setContent(intent); 46//设置页签指向的显示内容问activity 47 48mTabHos.addTab(newTabSpec); 49//添加页签 50} 51 52 }

------------------------------
三个菜单的布局与代码
------------------------------
会话布局:activity_conversation_ui.xml
1 < ?xml version="1.0" encoding="utf-8"?> 2 < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3xmlns:tools="http://schemas.android.com/tools" 4android:layout_width="match_parent" 5android:layout_height="match_parent" 6android:paddingBottom="@dimen/activity_vertical_margin" 7android:paddingLeft="@dimen/activity_horizontal_margin" 8android:paddingRight="@dimen/activity_horizontal_margin" 9android:paddingTop="@dimen/activity_vertical_margin" 10tools:context="com.sowsceo.sms.ConversationUI"> 11 12< TextView 13android:layout_width="match_parent" 14android:layout_height="match_parent" 15android:text="会话" 16android:textSize="50sp"/> 17 < /RelativeLayout>

  逻辑代码:ConversationUI.java
1 import android.app.Activity; 2 import android.support.v7.app.AppCompatActivity; 3 import android.os.Bundle; 4 5 /** 6* 会话 7*/ 8 public class ConversationUI extends Activity { 9 10@Override 11protected void onCreate(Bundle savedInstanceState) { 12super.onCreate(savedInstanceState); 13setContentView(R.layout.activity_conversation_ui); 14} 15 }

 
  -------------------------------------------
布局代码:activity_folder_ui.xml
< ?xml version="1.0" encoding="utf-8"?> < RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.sowsceo.sms.FolderUI"> < TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="文件夹" android:textSize="50sp" /> < /RelativeLayout>

 
  逻辑代码:FolderUI.java
1 import android.app.Activity; 2 import android.support.v7.app.AppCompatActivity; 3 import android.os.Bundle; 4 5 /** 6* 7* 创建者:风马一族 8* 时间: 2016/8/9 19:06 9* 说明:文件夹 10*/ 11 12 public class FolderUI extends Activity { 13 14@Override 15protected void onCreate(Bundle savedInstanceState) { 16super.onCreate(savedInstanceState); 17setContentView(R.layout.activity_folder_ui); 18} 19 }

 
----------------------------------
【风马一族_Android通过菜单的点击,跳转到不同界面】布局代码:activity_group_ui.xml
 

 
< ?xml version="1.0" encoding="utf-8"?>
< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.sowsceo.sms.FolderUI">

< TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="文件夹"
android:textSize="50sp" />
< /RelativeLayout>

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

    推荐阅读