2013-04-03 20 views
7

Hiện tại nó là hoạt động chính nhưng tôi muốn thay đổi nó thành hoạt động Danh mục. Đây có phải là vấn đề nằm ở đâu không?Làm cách nào để thay đổi cấp bậc gốc của một hoạt động?

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
    case android.R.id.home: 
     // This ID represents the Home or Up button. In the case of this 
     // activity, the Up button is shown. Use NavUtils to allow users 
     // to navigate up one level in the application structure. For 
     // more details, see the Navigation pattern on Android Design: 
     // 
     // http://developer.android.com/design/patterns/navigation.html#up-vs-back 
     // 
     NavUtils.navigateUpFromSameTask(this); 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
+0

Vấn đề chính xác là gì? – fiddler

+0

Khi tôi đang hoạt động trong danh mục, ví dụ: thể thao, tôi muốn quay lại hoạt động danh mục chứ không phải hoạt động chính là hoạt động khởi chạy – user2229066

Trả lời

14

Tới AndroidManifest.xml, thấy hoạt động thể thao của bạn và thêm mã này

<activity android:name="Sport" > 
    <meta-data 
     android:name="android.support.PARENT_ACTIVITY" 
     android:value="PARENT_ACTIVITY_PATH" /> 
</activity> 

thay PARENT_ACTIVITY_PATH với tên của hoạt động cha mẹ của bạn thêm cũng tên gói của bạn (ví dụ com.example.Categories).

0

Tắt @Mangusto. Sau khi thêm đường dẫn hoạt động gốc vào AndroidManifest, hãy thêm dòng này vào phương thức onCreate của hoạt động Thể thao của bạn getSupportActionBar().setDisplayHomeAsUpEnabled(true);

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