2013-04-03 58 views
7

目前它是主要活動,但我想將其更改爲類別活動。 問題出在哪裏?如何更改活動的層級父級?

@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

究竟是什麼問題? – fiddler

+0

當我參加類別活動時體育,我想回到類別活動,而不是主要的活動,這是發起活動 – user2229066

回答

14

轉到AndroidManifest.xml,找到你的體育活動,並添加以下代碼

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

替換PARENT_ACTIVITY_PATH與你的父母的活動還加入你的包名稱(例如com.example.Categories)的名稱。

0

@Mangusto。在您的AndroidManifest中添加父活動路徑後,在您的Sport活動的onCreate方法中添加此行getSupportActionBar().setDisplayHomeAsUpEnabled(true);

相關問題