您的位置:首页 > 移动开发 > Android开发

android底部菜单栏实现

2012-12-06 18:20 423 查看
一 TabHost

布局文件

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<!-- @android:id/tabcontent 这个id必须是指定的 -->

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
</FrameLayout>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<!-- @android:id/tabcontent 这个id必须是指定的 -->
<!-- android:tabStripEnabled="false"去掉选项下划线 -->

<TabWidget
android:id="@android:id/tabs"
android:tabStripEnabled="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#1AD6D6" >
</TabWidget>
</RelativeLayout>

</TabHost>


package com.tabhost1;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class TabHostDemo1Activity extends TabActivity {
private TabHost tabHost;
private Intent index,share,settting;

/**
*    <!-- android:tabStripEnabled="false"去掉选项下划线 -->貌似在2.2的系统上才有效,低于这个系统的可以参考这个文章
*
*    http://blog.csdn.net/west8623/article/details/7481895 */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost=getTabHost();
index=new Intent(this, IndexActivity.class);
tabHost.addTab(tabHost.newTabSpec("index").setIndicator("首页", getResources().getDrawable(R.drawable.bottom_item_index_bg)).setContent(index));

share=new Intent(this, ShareActivity.class);
tabHost.addTab(tabHost.newTabSpec("share").setIndicator("分享", getResources().getDrawable(R.drawable.bottom_item_share_bg)).setContent(share));

settting=new Intent(this,SettingActivity.class);
tabHost.addTab(tabHost.newTabSpec("setting").setIndicator("设置", getResources().getDrawable(R.drawable.bottom_item_set_bg)).setContent(settting));

tabHost.setCurrentTabByTag("share");//设置当前选中标签
}
}


package com.tabhost1;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class IndexActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
TextView textView=new TextView(this);
textView.setText("首页");
setContentView(textView);
}
}
省略两个Activity 跟IndexActivity一样

二 TabHost+RadioGroup
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: