Mono 平台 安卓 APP 菜单栏制作

介绍安卓APP 底布菜单的制作

效果图如下:

现在开始上Ui设计的代码:

Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <TabHost
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:id="@+id/tabHost1">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/linearLayout1">
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
            <RadioGroup
                android:id="@+id/bottom_group"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:background="@drawable/group_background"
                android:gravity="center_vertical"
                android:orientation="horizontal">
                <RadioButton
                    android:id="@+id/radio_home"
                    style="@style/radio_navigation_bar_bottom_tab"
                    android:checked="true"
                    android:drawableTop="@drawable/tab_home"
                    android:text="Tab1" />
                <RadioButton
                    android:id="@+id/radio_letter"
                    style="@style/radio_navigation_bar_bottom_tab"
                    android:drawableTop="@drawable/tab_reference"
                    android:text="Tab2"
                    android:enabled="true" />
                <RadioButton
                    android:id="@+id/radio_comment"
                    style="@style/radio_navigation_bar_bottom_tab"
                    android:drawableTop="@drawable/tab_reference"
                    android:text="Tab3"
                    android:enabled="true" />
                <RadioButton
                    android:id="@+id/radio_more"
                    style="@style/radio_navigation_bar_bottom_tab"
                    android:drawableTop="@drawable/tab_more"
                    android:text="Tab4" />
            </RadioGroup>
        </LinearLayout>
    </TabHost>
</LinearLayout>
这里是最重要的代码:(对应Main.axml)

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace Tab
{
    [Activity(Label = "Tab", MainLauncher = true, Icon = "@drawable/ic_launcher")]
    public class MainActivity : Activity, View.IOnClickListener
    {


        private RadioGroup group;
        private TabHost tabHost;
        private String tab_home_bar = "tab_home";
        private String tab_letter_bar = "tab_letter";
        private String tab_comment_bar = "tab_comment";
        private String tab_more_bar = "tab_more";



        private RadioButton radio_home;

        private RadioButton radio_letter;

        private RadioButton radio_comment;

    

        private RadioButton radio_more;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            init();
            LocalActivityManager localActMgr = new LocalActivityManager(this, false);
            localActMgr.DispatchCreate(bundle);
            tabHost.Setup(localActMgr);
            setNavigationBar();
        }

        private void init()
        {
            //group = FindViewById<RadioGroup>(Resource.Id.bottom_group);
            //group.SetOnClickListener(this);
            radio_home = FindViewById<RadioButton>(Resource.Id.radio_home);
            radio_letter = FindViewById<RadioButton>(Resource.Id.radio_letter);
            radio_comment = FindViewById<RadioButton>(Resource.Id.radio_comment);
           
            radio_more = FindViewById<RadioButton>(Resource.Id.radio_more);

            radio_home.SetOnClickListener(this);
            radio_letter.SetOnClickListener(this);
            radio_comment.SetOnClickListener(this);
         
            radio_more.SetOnClickListener(this);


            tabHost = FindViewById<TabHost>(Resource.Id.tabHost1);
        }

        private void setNavigationBar()
        {

            TabHost.TabSpec tab_home = tabHost.NewTabSpec(tab_home_bar);
            TabHost.TabSpec tab_letter = tabHost.NewTabSpec(tab_letter_bar);
            TabHost.TabSpec tab_comment = tabHost.NewTabSpec(tab_comment_bar);

            TabHost.TabSpec tab_more = tabHost.NewTabSpec(tab_more_bar);

            tab_home.SetIndicator(tab_home_bar).SetContent(new Intent(this, typeof(Activity1)));
            tab_letter.SetIndicator(tab_letter_bar).SetContent(new Intent(this, typeof(Activity2)));
            tab_comment.SetIndicator(tab_comment_bar).SetContent(new Intent(this, typeof(Activity3)));
        
            tab_more.SetIndicator(tab_more_bar).SetContent(new Intent(this, typeof(Activity5)));



            tabHost.AddTab(tab_home);
            tabHost.AddTab(tab_letter);
            tabHost.AddTab(tab_comment);
    
            tabHost.AddTab(tab_more);

            tabHost.CurrentTab = 1;
        }

        public void OnClick(View v)
        {
            switch (v.Id)
            {
                case Resource.Id.radio_home:
                    tabHost.SetCurrentTabByTag(tab_home_bar);
                    break;
                case Resource.Id.radio_letter:
                    tabHost.SetCurrentTabByTag(tab_letter_bar);
                    break;
                case Resource.Id.radio_comment:
                    tabHost.SetCurrentTabByTag(tab_comment_bar);
                    break;
                
                case Resource.Id.radio_more:
                    tabHost.SetCurrentTabByTag(tab_more_bar);
                    break;
            }
        }
    }
}

源码送上


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值