문제

I've followed the development pages on the android dev site, but I cannot get my action bar to split to the top and bottom of the screen.

I've got a menu xml defined with a couple of options:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@+id/stop_services"
    android:icon="@drawable/ic_launcher"
    android:title="@string/stop" 
    android:showAsAction="ifRoom|withText"/>
  <item android:id="@+id/start_services"
    android:icon="@drawable/pushpin"
    android:title="@string/start" 
    android:showAsAction="ifRoom|withText"/>
</menu>

In my manifest I've set the uiOption to:

<activity
  android:label="@string/app_name"
  android:name=".ProxilenceHome" 
  uiOptions="splitActionBarWhenNarrow" >

I load the menu items in the activity as follows:

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.home_menu, menu);
    return true;
}

But when testing the application, the action bar never splits. Does anyone know the problem/ if I've missed anything out?

Thanks a lot.

도움이 되었습니까?

해결책

Using android:uiOptions="splitActionBarWhenNarrow" works for me.

Without the "android:" it does not work

다른 팁

using this in landscape mode navigation tabs split but in portrait mode it is not work.

    final ActionBar bar = this.getActionBar();
        bar.setDisplayHomeAsUpEnabled(false);
bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);




mTabsAdapter = new TabsAdapter(this, mViewPager);
    Tab tab1=mTabsAdapter.addTab(bar.newTab().setText("DemoGraphics"),ListFragmentDemo.PatientFragment.class, null);

public boolean onCreateOptionsMenu(Menu menu)
    {

        MenuInflater inflater=getMenuInflater();
        inflater.inflate(R.menu.mainmenu, menu);
        super.onCreateOptionsMenu(menu); 

        return true;
    }

mainmenu.xml

    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_dCollection"
         android:icon="@drawable/overflowmenu"
         android:showAsAction="ifRoom|withText"
    >
     <menu>
     <item android:id="@+id/menu_demo"

           android:title="DemoGraphics" />
     <item android:id="@+id/menu_visits"  
           android:title="Visits" />
     <item android:id="@+id/menu_vitals"  
           android:title="Vitals" />
     </menu>
    </item>
     <item android:id="@+id/add" android:showAsAction="ifRoom" android:title="Add" android:icon="@drawable/ic_action_open"></item>
     <item android:id="@+id/previous" android:showAsAction="ifRoom" android:title="Back" android:icon="@drawable/back"></item>
        <item android:id="@+id/nextFragment" android:showAsAction="ifRoom" android:title="Next" android:icon="@drawable/next"></item>
     <item android:id="@+id/menu_search" android:showAsAction="ifRoom" android:title="Search" android:actionViewClass="android.widget.SearchView" android:icon="@drawable/search" />
 </menu>

in manifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:installLocation="preferExternal"
    package="savy.exam.actionbartabspager"
    android:versionCode="1"
    android:versionName="1.0"
    android:uiOptions="splitActionBarWhenNarrow"
     >

Try to add this line in your menu xml:

<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto" >

Then in your item element:

myapp:showAsAction="always|withText"

It helped me.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top