将TabHost的标签放在底部
直接上代码
主代码:
1 package sdut; 2 3 import com.example.sdutfriends.R; 4 5 import android.app.AlertDialog; 6 import android.app.TabActivity; 7 import android.content.DialogInterface; 8 import android.content.Intent; 9 import android.os.Bundle; 10 import android.view.KeyEvent; 11 import android.view.Window; 12 import android.widget.RadioGroup; 13 import android.widget.RadioGroup.OnCheckedChangeListener; 14 import android.widget.TabHost; 15 import android.widget.TabHost.TabSpec; 16 17 public class SdutMainActivity extends TabActivity{ 18 private TabHost mth; 19 private RadioGroup radioGroup; 20 @Override 21 protected void onCreate(Bundle savedInstanceState) { 22 // TODO Auto-generated method stub 23 super.onCreate(savedInstanceState); 24 //去除标题 25 requestWindowFeature(Window.FEATURE_NO_TITLE); 26 setContentView(R.layout.sdut_activity); 27 28 //初始化底部菜单栏 29 mth = this.getTabHost(); 30 31 TabSpec str1 = mth.newTabSpec("function_1").setIndicator("功能1"); 32 str1.setContent(new Intent(SdutMainActivity.this,SdutFindOldman.class)); 33 mth.addTab(str1); 34 35 TabSpec str2 = mth.newTabSpec("function_2").setIndicator("功能2"); 36 str2.setContent(new Intent(SdutMainActivity.this,SdutFindActivity.class)); 37 mth.addTab(str2); 38 39 TabSpec str3 = mth.newTabSpec("function_3").setIndicator("功能3"); 40 str3.setContent(new Intent(SdutMainActivity.this,SdutFindOldman.class)); 41 mth.addTab(str3); 42 43 TabSpec str4 = mth.newTabSpec("function_4").setIndicator("功能4"); 44 str4.setContent(new Intent(SdutMainActivity.this,SdutFindOldman.class)); 45 mth.addTab(str4); 46 47 TabSpec str5 = mth.newTabSpec("function_5").setIndicator("功能5"); 48 str5.setContent(new Intent(SdutMainActivity.this,SdutFindOldman.class)); 49 mth.addTab(str5); 50 51 //底部菜单栏点击事件 52 radioGroup = (RadioGroup) findViewById(R.id.main_radio); 53 radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { 54 55 @Override 56 public void onCheckedChanged(RadioGroup group, int checkedId) { 57 // TODO Auto-generated method stub 58 switch(checkedId) 59 { 60 case R.id.radio_button0:mth.setCurrentTabByTag("function_1");break; 61 case R.id.radio_button1:mth.setCurrentTabByTag("function_2");break; 62 case R.id.radio_button2:mth.setCurrentTabByTag("function_3");break; 63 case R.id.radio_button3:mth.setCurrentTabByTag("function_4");break; 64 case R.id.radio_button4:mth.setCurrentTabByTag("function_5");break; 65 66 } 67 } 68 }); 69 } 70 71 //设置 返回键的 按钮响应事件 72 @Override 73 public boolean dispatchKeyEvent(KeyEvent event) { 74 // TODO Auto-generated method stub 75 if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_BACK) 76 { 77 new AlertDialog.Builder(this).setCancelable(false).setTitle("温馨提示").setMessage("您确定要退出吗?").setPositiveButton("确定", new DialogInterface.OnClickListener() 78 { 79 public void onClick(DialogInterface dialog, int which) 80 { 81 finish(); 82 } 83 }).setNegativeButton("取消", new DialogInterface.OnClickListener() 84 { 85 public void onClick(DialogInterface dialog, int which) 86 { 87 } 88 }).show(); 89 return true;// 不知道返回true或是false有什么区别?? 90 } 91 92 return super.dispatchKeyEvent(event); 93 } 94 }