标签栏在Android中 [英] Tab Bar in Android

查看:222
本文介绍了标签栏在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这些程序的帮助下,我创建的标签。你可以看一下下面的codeS。

HomeActivity.java:

 包com.sit.fth.activity;

    进口android.app.ActionBar;
    进口android.app.ActionBar.Tab;
    进口android.content.Intent;
    进口android.os.Bundle;
    进口android.support.v4.view.ViewPager;
    进口android.util.Log;
    进口android.view.WindowManager;


    公共类HomeActivity扩展BaseActivity工具
            VideoFragment.OnVideoSelectedListener,

            AboutFragment.OnAboutFragmentSelectedListener,

            AnnouncenentFragment.OnAnnouncementSelectedListener,

            GalleryFragment.OnGalItemSelectedListener,

            MagzineFragment.OnMagzineSelectedListener {

        民营动作条actionabar;
        私人ViewPager viewpager;
        私人LiveStreamFragment liveStreamFragment;
        私人应用程序数据应用程序数据;
        私人FragmentManager FM;
        私人MyFragmentPagerAdapter fragmentPagerAdapter;
        //私人HomeBaseFragment片段;

        @覆盖
        保护无效的onCreate(捆绑为arg0){
            super.onCreate(为arg0);

            的setContentView(R.layout.activity_main);
            APPDATA =((GemsApplication)this.getApplication())getAppData()。


            actionabar = getActionBar();
            actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);



            liveStreamFragment =新LiveStreamFragment();

            viewpager =(ViewPager)findViewById(R.id.pager);
            FM = getSupportFragmentManager();

            / **定义一个侦听pageChange * /
            ViewPager.SimpleOnPageChangeListener pageChangeListener =新ViewPager.SimpleOnPageChangeListener(){
                @覆盖
                公共无效onPageSelected(INT位置){
                    super.onPageSelected(位置);
                    actionabar.setSelectedNavigationItem(位置);
                }
            };

            / **的pageChange听者设定在viewPager * /
            viewpager.setOnPageChangeListener(pageChangeListener);

            / **创建FragmentPagerAdapter的实例* /
            fragmentPagerAdapter =新MyFragmentPagerAdapter(FM);

            viewpager.setAdapter(fragmentPagerAdapter);
            actionabar.setDisplayShowTitleEnabled(真正的);

            / **定义选项卡监听器* /
            ActionBar.TabListener tabListener =新ActionBar.TabListener(){

                @覆盖
                公共无效onTabReselected(标签为arg0,
                        android.app.FragmentTransaction ARG1){

                }

                @覆盖
                公共无效onTabSelected(标签选项卡,
                        android.app.FragmentTransaction英尺){
                    viewpager.setCurrentItem(tab.getPosition());

                }

                @覆盖
                公共无效onTabUnselected(标签选项卡,
                        android.app.FragmentTransaction英尺){

                }
            };


                    TAB键= actionabar.newTab()的setText(的getString(R.string.str_home))
                            .setTabListener(tabListener);
                    actionabar.addTab(标签);
                    标签= actionabar.newTab()的setText(的getString(R.string.str_video))
                            .setTabListener(tabListener);
                    actionabar.addTab(标签);
                    标签= actionabar.newTab()的setText(的getString(R.string.str_gal))
                            .setTabListener(tabListener);
                    actionabar.addTab(标签);
                    标签= actionabar.newTab()的setText(的getString(R.string.str_announcements))
                            .setTabListener(tabListener);
                    actionabar.addTab(标签);

                    标签= actionabar.newTab()
                            .setText(的getString(R.string.str_magazines))
                            .setTabListener(tabListener);
                    actionabar.addTab(标签);

                    标签= actionabar.newTab()的setText(的getString(R.string.str_conduct))
                            .setTabListener(tabListener);
                    actionabar.addTab(标签);


        }
    }
 

我需要移动标签的screen.I的底部我感到困惑,因为我加了标签 HomeActivity的帮助。 Java编码不是从XML布局

我不知道如何移动卡到screen.Anybody的底部可以帮助我these.Thank你。<​​/ P>

解决方案

此链接:配售我的动作条在底部

在谷歌的默认操作栏不会在任何情况下,在底部出现。因为它似乎其他人提到,splitActionBarWhenNarrow仅将您的ActionBar的一个​​子集(如片等)上的屏幕的底部时,该设备是窄的。不幸的是,如果你想实现像在屏幕的底部接口的动作条,你必须自己(一个快速搜索发现这个例子中)实现它,因为我还没有看到任何图书馆这样做给你。

在所有的,不过,我不推荐它,因为它违反了无缝的设计原则,设计文件被打破,其中的ActionBar类型的控件将用户的期望 - 一个Android用户非常习惯做的事情一定的方式,你需要一个pretty的令人信服的理由打破这种预期。

也看到此链接: http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar

这里是一个示例:http://android-ed.blogspot.com/2011/12/using-actionbar-at-bottom-of-screen.html

With the help of these program, I created the Tabs. you can look at a below Codes.

HomeActivity.java:

 package com.sit.fth.activity;

    import android.app.ActionBar;
    import android.app.ActionBar.Tab;
    import android.content.Intent;
    import android.os.Bundle;
    import android.support.v4.view.ViewPager;
    import android.util.Log;
    import android.view.WindowManager;


    public class HomeActivity extends BaseActivity implements
            VideoFragment.OnVideoSelectedListener,

            AboutFragment.OnAboutFragmentSelectedListener,

            AnnouncenentFragment.OnAnnouncementSelectedListener,

            GalleryFragment.OnGalItemSelectedListener,

            MagzineFragment.OnMagzineSelectedListener {

        private ActionBar actionabar;
        private ViewPager viewpager;
        private LiveStreamFragment liveStreamFragment;
        private AppData appData;
        private FragmentManager fm;
        private MyFragmentPagerAdapter fragmentPagerAdapter;
        // private HomeBaseFragment fragment;

        @Override
        protected void onCreate(Bundle arg0) {
            super.onCreate(arg0);

            setContentView(R.layout.activity_main);
            appData = ((GemsApplication) this.getApplication()).getAppData();


            actionabar = getActionBar();
            actionabar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);



            liveStreamFragment = new LiveStreamFragment();

            viewpager = (ViewPager) findViewById(R.id.pager);
            fm = getSupportFragmentManager();

            /** Defining a listener for pageChange */
            ViewPager.SimpleOnPageChangeListener pageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
                @Override
                public void onPageSelected(int position) {
                    super.onPageSelected(position);
                    actionabar.setSelectedNavigationItem(position);
                }
            };

            /** Setting the pageChange listner to the viewPager */
            viewpager.setOnPageChangeListener(pageChangeListener);

            /** Creating an instance of FragmentPagerAdapter */
            fragmentPagerAdapter = new MyFragmentPagerAdapter(fm);

            viewpager.setAdapter(fragmentPagerAdapter);
            actionabar.setDisplayShowTitleEnabled(true);

            /** Defining tab listener */
            ActionBar.TabListener tabListener = new ActionBar.TabListener() {

                @Override
                public void onTabReselected(Tab arg0,
                        android.app.FragmentTransaction arg1) {

                }

                @Override
                public void onTabSelected(Tab tab,
                        android.app.FragmentTransaction ft) {
                    viewpager.setCurrentItem(tab.getPosition());

                }

                @Override
                public void onTabUnselected(Tab tab,
                        android.app.FragmentTransaction ft) {

                }
            };


                    Tab tab = actionabar.newTab().setText(getString(R.string.str_home))
                            .setTabListener(tabListener);
                    actionabar.addTab(tab);
                    tab = actionabar.newTab().setText(getString(R.string.str_video))
                            .setTabListener(tabListener);
                    actionabar.addTab(tab);
                    tab = actionabar.newTab().setText(getString(R.string.str_gal))
                            .setTabListener(tabListener);
                    actionabar.addTab(tab);
                    tab = actionabar.newTab().setText(getString(R.string.str_announcements))
                            .setTabListener(tabListener);
                    actionabar.addTab(tab);

                    tab = actionabar.newTab()
                            .setText(getString(R.string.str_magazines))
                            .setTabListener(tabListener);
                    actionabar.addTab(tab);

                    tab = actionabar.newTab().setText(getString(R.string.str_conduct))
                            .setTabListener(tabListener);
                    actionabar.addTab(tab);  


        }
    }

I need to move a tab to the bottom of the screen.I am getting confused because I add a tabs with the help of HomeActivity.java coding not from xml layout.

I doesn't know how to move the tab to the bottom of the screen.Anybody can help me with these.Thank You.

解决方案

this link : Placing my ActionBar at the bottom

The google default action bar does not in any case appear on the bottom. As it seems others have mentioned, splitActionBarWhenNarrow only puts a subset of your ActionBar (like tabs, etc) on the bottom of the screen when the device is narrow. Unfortunately, if you want to implement an ActionBar like interface on the bottom of the screen, you'll have to implement it yourself (a quick search finds this example), as I haven't seen any Libraries to do this for you.

In all, though, I would recommend against it, as it violates the Seamlessness design principle in the design documents by breaking user expectations of where ActionBar type controls will be - An android user is ideally used to doing things a certain way, and you would need a pretty compelling reason to break that expectation.

too see this link : http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar

and here is a sample : http://android-ed.blogspot.com/2011/12/using-actionbar-at-bottom-of-screen.html

这篇关于标签栏在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆