【风马一族_Android】通过菜单的点击,跳转到不同界面
---恢复内容开始---
布局的代码:activity_main.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 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 <TabHost 9 android:id="@android:id/tabhost" 10 android:layout_width="match_parent" 11 android:layout_height="match_parent"> 12 13 <LinearLayout 14 android:layout_width="match_parent" 15 android:layout_height="match_parent" 16 android:orientation="vertical"> 17 18 <TabWidget 19 android:id="@android:id/tabs" 20 android:layout_width="match_parent" 21 android:layout_height="wrap_content"></TabWidget> 22 23 <FrameLayout 24 android:id="@android:id/tabcontent" 25 android:layout_width="match_parent" 26 android: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 10 private TabHost mTabHos; 11 12 @Override 13 protected void onCreate(Bundle savedInstanceState) { 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.activity_main); 16 17 initTabHost(); 18 } 19 20 /** 21 * 初始化tabHost 22 */ 23 private void initTabHost() { 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 * @param tag 标记 35 * @param label 标题 36 * @param icon 图标 37 * @param intent 指向的activity 38 */ 39 private void addTabSpec(String tag,String label,int icon,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 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 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 <TextView 13 android:layout_width="match_parent" 14 android:layout_height="match_parent" 15 android:text="会话" 16 android: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 11 protected void onCreate(Bundle savedInstanceState) { 12 super.onCreate(savedInstanceState); 13 setContentView(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 15 protected void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 setContentView(R.layout.activity_folder_ui); 18 } 19 }
----------------------------------
布局代码: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>
---恢复内容结束---
每天完成一件事。
不管是为了什么。