• 大小: 14.11MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-07-02
  • 语言: Java
  • 标签: xamarin  

资源简介

xamarin android 使用fragment底部导航栏,原文链接http://blog.csdn.net/kebi007/article/month/2017/04

资源截图

代码片段和文件信息

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using FragmentDemo.Fragments;
using Android.Support.V7.App;
using Android.Util;
namespace FragmentDemo
{
    [Activity(Label = “FragmentDemo“ MainLauncher = true Icon = “@drawable/icon“ Theme = “@android:style/Theme.Light.NotitleBar“)]
    public class MainActivity : Activity
    {
        private TextView txt_chat;
        private TextView txt_contacts;
        private TextView txt_more;
        private frameLayout ly_content;
        private MyFragment fg1 fg2 fg3;
        private FragmentManager fManager;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            ly_content = (frameLayout)FindViewById(Resource.Id.ly_content);
            MyFragment fg = new MyFragment(“第一个fragment“);
            txt_chat = (TextView)FindViewById(Resource.Id.txt_chat);
            txt_contacts = (TextView)FindViewById(Resource.Id.txt_contacts);
            txt_more = (TextView)FindViewById(Resource.Id.txt_more);
            bindViews();
            txt_chat.PerformClick();
        }
        //ui组件初始化与事件绑定
        private void bindViews()
        {
          
            txt_chat.Click += (s e) => { onclick(txt_chat); };
            txt_contacts.Click += delegate { onclick(txt_contacts); };
            txt_more.Click += delegate { onclick(txt_more); };
        }
        //隐藏所有Fragment
        private void hideAllFragment(FragmentTransaction fragmentTransaction)
        {
            if (fg1 != null) fragmentTransaction.Hide(fg1);
            if (fg2 != null) fragmentTransaction.Hide(fg2);
            if (fg3 != null) fragmentTransaction.Hide(fg3);
        }
        //重置所有文本的选中状态
        private void setSelected()
        {
            txt_chat.Selected =false;
            txt_contacts.Selected = false;
            txt_more.Selected = false;
        }
        //单击事件
        public void onclick(View v)
        { 
                FragmentTransaction fTransaction = FragmentManager.BeginTransaction();
                hideAllFragment(fTransaction);
                switch (v.Id)
                {
                    case Resource.Id.txt_chat:
                        setSelected();
                        txt_chat.Selected = true;
                        if (fg1 == null)
                        {
                            fg1 = new MyFragment(“聊天Fragment“);
                            fTransaction.Add(Resource.Id.ly_content fg1);
                        }
                        else{fTransaction.Show(fg1);}break;
                    case Resource.Id.txt_contacts:
                        setSelected();
                        txt_contacts.Selected = true;
                        if (fg2 == null)
                        {
                          

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        620  2016-11-20 20:03  FragmentDemo\Assets\AboutAssets.txt

     文件      58368  2017-04-21 02:06  FragmentDemo\bin\Debug\FragmentDemo.dll

     文件       2693  2017-04-21 02:06  FragmentDemo\bin\Debug\FragmentDemo.dll.mdb

     文件    6234028  2017-04-21 02:07  FragmentDemo\bin\Debug\FragmentDemo.FragmentDemo-Signed.apk

     文件    6269154  2017-04-21 02:06  FragmentDemo\bin\Debug\FragmentDemo.FragmentDemo.apk

     文件      28160  2017-04-21 02:06  FragmentDemo\bin\Debug\FragmentDemo.pdb

     文件      44745  2017-04-21 02:06  FragmentDemo\bin\Debug\Java.Interop.dll.mdb

     文件    7604642  2017-04-21 02:06  FragmentDemo\bin\Debug\Mono.Android.dll.mdb

     文件    1496781  2017-04-21 02:06  FragmentDemo\bin\Debug\mscorlib.dll.mdb

     文件     137422  2017-04-21 02:06  FragmentDemo\bin\Debug\System.ComponentModel.Composition.dll.mdb

     文件     359097  2017-04-21 02:06  FragmentDemo\bin\Debug\System.Core.dll.mdb

     文件     768028  2017-04-21 02:06  FragmentDemo\bin\Debug\System.dll.mdb

     文件      48067  2017-04-21 02:06  FragmentDemo\bin\Debug\System.Net.Http.dll.mdb

     文件     322073  2017-04-21 02:06  FragmentDemo\bin\Debug\System.Runtime.Serialization.dll.mdb

     文件      89254  2017-04-21 02:06  FragmentDemo\bin\Debug\System.ServiceModel.Internals.dll.mdb

     文件     953244  2017-04-21 02:06  FragmentDemo\bin\Debug\System.xml.dll.mdb

     文件      50083  2017-04-21 02:06  FragmentDemo\bin\Debug\System.xml.Linq.dll.mdb

     文件    1973248  2016-01-19 18:12  FragmentDemo\bin\Debug\Xamarin.Android.Support.v4.dll

     文件     888320  2016-01-19 18:12  FragmentDemo\bin\Debug\Xamarin.Android.Support.v7.AppCompat.dll

     文件       5803  2017-04-21 00:07  FragmentDemo\FragmentDemo.csproj

     文件        261  2016-11-20 20:16  FragmentDemo\FragmentDemo.csproj.user

     文件        872  2017-04-21 01:53  FragmentDemo\Fragments\MyFragment.cs

     文件        160  2016-11-20 20:03  FragmentDemo\GettingStarted.Xamarin

     文件       3816  2017-04-21 02:06  FragmentDemo\MainActivity.cs

     文件        290  2016-11-21 21:35  FragmentDemo\packages.config

     文件        313  2016-11-21 23:55  FragmentDemo\Properties\AndroidManifest.xml

     文件       1094  2016-11-20 20:03  FragmentDemo\Properties\AssemblyInfo.cs

     文件       1736  2016-11-20 20:03  FragmentDemo\Resources\AboutResources.txt

     文件        269  2016-11-20 23:44  FragmentDemo\Resources\drawable\tab_menu_chat.xml

     文件        277  2016-11-20 23:44  FragmentDemo\Resources\drawable\tab_menu_contacts.xml

............此处省略30个文件信息

评论

共有 条评论