2011-12-07 21 views
6

Tôi đã theo dõi các trang phát triển trên trang web dev android, nhưng tôi không thể nhận thanh tác vụ của mình được chia thành đầu và cuối màn hình.Không thể lấy Thanh tác vụ Chia tách Android 4.0 hoạt động

Tôi đã có một xml đơn được xác định với một vài lựa chọn:

<?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> 

Trong manifest của tôi, tôi đã thiết lập các uiOption tới:

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

tôi tải các mục trình đơn trong hoạt động như sau:

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

Nhưng khi thử nghiệm ứng dụng, thanh tác vụ không bao giờ tách. Có ai biết vấn đề/nếu tôi đã bỏ lỡ bất cứ điều gì không?

Cảm ơn rất nhiều.

+0

Bạn có đang chạy ứng dụng trên thiết bị ICS hoặc trình giả lập không? –

+0

Hiện có trên thiết bị. Sẽ thử giả lập quá. – clamped

+0

Được rồi thử trên trình mô phỏng, không hoạt động ở đó. – clamped

Trả lời

26

Sử dụng android:uiOptions="splitActionBarWhenNarrow" phù hợp với tôi.

Nếu không có "android:", nó không hoạt động

+0

Tuyệt vời, nghĩ rằng nó có thể là thứ đơn giản mà tôi đã bỏ lỡ. Cảm ơn. – clamped

0

bằng cách sử dụng trong tab điều hướng chế độ nằm ngang nhưng ở chế độ dọc thì không hoạt động.

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> 

trong tập tin manifest.xml

<?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" 
    > 
+0

xin lỗi .i đã nhận lỗi của tôi.chúng tôi tạo cấu hình thiết bị theo cách thủ công cho trình mô phỏng cho rằng nó không hoạt động. Nhưng khi tôi đang sử dụng cấu hình deivce hiện có, nó hoạt động – amy

0

Cố gắng thêm dòng này trong xml menu của bạn:

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

Sau đó, trong mục của bạn phần tử:

myapp:showAsAction="always|withText" 

Nó đã giúp tôi.

Các vấn đề liên quan