1

我正在使用 actionbarsherlock 的 ActionBar,当您第一次以横向或横向运行应用程序时,选项卡会显示为Tabs Mode. 将方向更改为纵向后,导航模式仍处于Tabs. 第二次更改horizontal选项卡的方向时显示为 aList并且仅显示父项,其余项被隐藏。听说这是安卓的bug,list如果标签太多不适合屏幕,系统会自动更改导航模式。但问题是我第一次加载应用程序时,它tabs甚至水平显示为模式。顺便说一句,我创建了100 个标签

此图像是水平视图。顶部的第一张图像只是我将手机的方向更改为纵向然后返回横向后的结果。
在此处输入图像描述


我的清单文件中有这段代码,

android:configChanges="orientation|screenSize"

主要活动

 public void onConfigurationChanged(Configuration newConfig) {
         ActionBar ab = getSupportActionBar();
             ab.setDisplayShowTitleEnabled(false);

             if(ab.getNavigationMode() != ActionBar.NAVIGATION_MODE_TABS){
                 ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

             }
        super.onConfigurationChanged(newConfig);
}

只是为了确保我也将代码放在靠近setContentView

        final ActionBar ab = getSupportActionBar();
        ab.setDisplayShowTitleEnabled(false);
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

更新:

我处理的原因是onConfigurationChanged因为我得到了Null Pointer Exception

日志猫

08-05 15:36:18.486: E/AndroidRuntime(30044): FATAL EXCEPTION: main
08-05 15:36:18.486: E/AndroidRuntime(30044): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.actionbarsherlock.sample.styled/com.actionbarsherlock.sample.styled.MainActivity}: java.lang.NullPointerException
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3512)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.app.ActivityThread.access$700(ActivityThread.java:130)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.os.Looper.loop(Looper.java:137)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.app.ActivityThread.main(ActivityThread.java:4745)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at java.lang.reflect.Method.invokeNative(Native Method)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at java.lang.reflect.Method.invoke(Method.java:511)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at dalvik.system.NativeStart.main(Native Method)
08-05 15:36:18.486: E/AndroidRuntime(30044): Caused by: java.lang.NullPointerException
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.nineoldandroids.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:504)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.nineoldandroids.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:410)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.nineoldandroids.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:538)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:928)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:951)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.nineoldandroids.animation.ObjectAnimator.start(ObjectAnimator.java:385)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.actionbarsherlock.sample.styled.MainActivity.rotateLeftFrag(MainActivity.java:218)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.actionbarsherlock.sample.styled.MainActivity.onTabSelected(MainActivity.java:256)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.actionbarsherlock.internal.app.ActionBarWrapper$TabWrapper.onTabSelected(ActionBarWrapper.java:356)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.android.internal.app.ActionBarImpl.selectTab(ActionBarImpl.java:570)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.android.internal.app.ActionBarImpl.setSelectedNavigationItem(ActionBarImpl.java:356)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.android.internal.app.ActionBarImpl.setNavigationMode(ActionBarImpl.java:1158)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.actionbarsherlock.internal.app.ActionBarWrapper.setNavigationMode(ActionBarWrapper.java:216)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.actionbarsherlock.sample.styled.MainActivity.showTabsNav(MainActivity.java:244)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at com.actionbarsherlock.sample.styled.MainActivity.onCreate(MainActivity.java:82)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.app.Activity.performCreate(Activity.java:5008)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-05 15:36:18.486: E/AndroidRuntime(30044):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-05 15:36:18.486: E/AndroidRuntime(30044):    ... 12 more
4

1 回答 1

1

它是 android 中选项卡的默认行为。如果水平/纵向方向的选项卡没有更多空间,则它将转换为列表。

现在,如果您仍然希望所有选项卡不在列表中,那么我建议您查看ViewPager的这个示例,之后您应该将该 FragmentActivity 添加到您的 SherlockFragmentActivity 中。只需检查下面的示例代码我正在做什么,这将帮助您拥有任何方向的所有选项卡。

public class TestSampleTabDefault extends SherlockActivity{

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

    }
    @SuppressLint("NewApi")
    public static class SampleTabsDefault extends FragmentActivity implements ServiceConnection {
        private static final String[] CONTENT = new String[] { "Albums", "Artists", "Songs", "Playlist","Genre","Recently Played","Easy Transfer" };
        Handler mHandler;
        //Runnable mRunnable;
        private ServiceToken mToken;
        private IRemoteService  mIRemoteService;
        public static ViewPager pager;
        public static int index = 0;
        public static android.app.ActionBar mActionBar;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.simple_tabs);

            //getSupportActionBar().setHomeButtonEnabled(true);
            //ActionBar bar = getSupportActionBar();
            //bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            //bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

            FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager());

            pager = (ViewPager)findViewById(R.id.pager);
            pager.setAdapter(adapter);

            /*getSupportActionBar().setTitle(name);
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);*/

            TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator);
            indicator.setViewPager(pager);

            index = getIntent().getExtras().getInt("index");
            if(index >0){
                indicator.setCurrentItem(index);
            }

        }

        class GoogleMusicAdapter extends FragmentPagerAdapter {
             private final FragmentManager mFragmentManager;
             private Fragment mFragmentAtPos0;
            public GoogleMusicAdapter(FragmentManager fm) {
                super(fm);
                mFragmentManager = fm;
            }
            @Override
            public Fragment getItem(int position) {
               // return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
                Fragment fm = null;

                if(position==0){// LOAD ALBUMS
                    fm = ArtistList.ArtistListFragment.newInstance();
                    return fm;

                }else if(position==1){// LOAD ARTISTS
                    //Toast.makeText(getApplicationContext(), "Select Album", Toast.LENGTH_SHORT).show();
                    fm = ArtistList.ArtistListFragment.newInstance();
                    return fm;
                }else if(position==2){// LOAD SONGS
                    fm = SongsList.SongsListFragment.newInstance(); 
                    return fm;
                }else if(position==3){   // PLaylist
                    fm = PlaylistList.PlayListFragment.newInstance();
                    return fm;
                }else if(position==4){ // Genre List
                    fm = GenreList.GenreListFragment.newInstance();
                    return fm;
                }else if(position==5){ // Recent List
                    fm = RecentAddedList.RecentListFragment.newInstance();
                    return fm;
                }else{
                    fm = TestFragment.newInstance(CONTENT[position]);
                }
                return fm;


            }

            @Override
            public CharSequence getPageTitle(int position) {
                return CONTENT[position % CONTENT.length].toUpperCase();
            }

            @Override
            public int getCount() {
              return CONTENT.length;
            }

            @Override
            public int getItemPosition(Object object)
            {
                if (object instanceof AlbumListFragment && mFragmentAtPos0 instanceof TestFragment)
                    return POSITION_NONE;
                return POSITION_UNCHANGED;
            }

        }

    }
}

希望这会帮助你。祝一切顺利。如果你在这方面遇到任何困难,请告诉我。

于 2013-08-05T07:40:53.553 回答