android底部菜单栏实现

一 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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值