Android栏中的标签栏

时间:2014-05-23 05:15:53

标签: android tabs android-actionbar

在这些程序的帮助下,我创建了Tabs。你可以查看下面的代码。

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);  


        }
    }

我需要将标签移到屏幕底部。我感到困惑,因为我在tabs的帮助下添加了HomeActivity.java coding not from xml layout

我不知道如何将标签移动到屏幕的底部。任何人都可以帮助我。谢谢。

1 个答案:

答案 0 :(得分:1)

此链接:Placing my ActionBar at the bottom

谷歌默认操作栏在任何情况下都不会显示在底部。正如其他人所提到的,当设备很窄时,splitActionBarWhenNarrow只会在屏幕底部放置一个ActionBar的子集(如制表符等)。不幸的是,如果你想在屏幕底部实现类似ActionBar的接口,你必须自己实现它(快速搜索找到这个例子),因为我还没有看到任何库来执行此操作对你而言。

总而言之,我建议不要这样做,因为它违反了设计文档中的无缝设计原则,打破了用户对ActionBar类型控件所在位置的期望 - 一个Android用户理想地习惯于以某种方式做事,你需要一个非常令人信服的理由来打破这种期望。

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