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

时间:2021-09-27 03:24:14

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

布局的代码:activity_main.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.MainActivity"> <TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>

逻辑代码 :MainActivity.java  

 import android.app.TabActivity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost; public class MainActivity extends TabActivity { private TabHost mTabHos; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); initTabHost();
} /**
* 初始化tabHost
*/
private void initTabHost() {
mTabHos = (TabHost) findViewById(android.R.id.tabhost); addTabSpec("conversation","会话",R.drawable.tab_conversation,new Intent(this,ConversationUI.class));
addTabSpec("folder","文件夹",R.drawable.tab_folder,new Intent(this,FolderUI.class));
addTabSpec("group","群组",R.drawable.tab_group,new Intent(this,GroupUI.class)); } /**
* 添加一个页签
* @param tag 标记
* @param label 标题
* @param icon 图标
* @param intent 指向的activity
*/
private void addTabSpec(String tag,String label,int icon,Intent intent){
TabHost.TabSpec newTabSpec = mTabHos.newTabSpec(tag); newTabSpec.setIndicator(label,getResources().getDrawable(icon));
//设置页签的标题与图标 newTabSpec.setContent(intent);
//设置页签指向的显示内容问activity mTabHos.addTab(newTabSpec);
//添加页签
} }

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

三个菜单的布局与代码

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

会话布局:activity_conversation_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.ConversationUI"> <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="会话"
android:textSize="50sp"/>
</RelativeLayout>

逻辑代码:ConversationUI.java

 import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; /**
* 会话
*/
public class ConversationUI extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conversation_ui);
}
}

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

布局代码: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

 import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; /**
*
* 创建者:风马一族
* 时间: 2016/8/9 19:06
* 说明:文件夹
*/ public class FolderUI extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_folder_ui);
}
}

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

布局代码: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>

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