我正在使用 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