Android ActionBar will not be split on device

I know that there were a lot of ActionBar questions, but they don't seem to address my issue. I can spit on the emulator in the ActionBar, but when I run my program on my device (Nexus 7 portrait mode), the ActionBar will not be split. All the icons "accumulate" on top, even my tabs create a drop-down list. I tried to get the problem by making the menu item names very long, and I have them: android: showAsAction = "always | withText". To be sure, I took an example code, ran it on an emulator, saw that it was working, and then put it on my device to no avail. Here is my manifest:

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/MyTheme"> <activity android:name=".MainActivity" android:uiOptions="splitActionBarWhenNarrow" android:label="@string/title_activity_main"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 

I browsed the web but cannot find a solution. Any help is appreciated.

+6
source share
2 answers

According to this SO> element, an ActionBar is only split when the available width is less than 480dp. According to Dianne Hackborn in this Google article , the portrait width of the Nexus 7 is 600dp. So the reason is not broken there.

I agree with you that splitting should depend on the relationship between the available space and the displayed items, not just the available space.

+7
source

I know this question is quite old, but I found a way to get the action bar to betom on Nexus 7 (and other devices), and I decided to share my solution:

Put this code in your activity:

 /** * {@inheritDoc} */ @Override public Resources getResources() { return new ResourceFix(super.getResources()); } private class ResourceFix extends Resources { private int targetId = 0; ResourceFix(Resources resources) { super(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration()); targetId = Resources.getSystem().getIdentifier("split_action_bar_is_narrow", "bool", "android"); } /** * {@inheritDoc} */ @Override public boolean getBoolean(int id) throws Resources.NotFoundException { return targetId == id || super.getBoolean(id); } } 

This will cause the internal value of split_action_bar_is_narrow to be true. This may not be the best way to do this, but it seems to be the only way I've found.

+7
source

All Articles