简体   繁体   English

如何更改活动的层次结构父级?

[英]How do I change the hierarchy parent of an activity?

At the moment it is main activity but I want to change it to the Categories activity. 目前它是主要活动,但我想将其更改为Categories活动。 Is this where the problem lies? 这是问题所在吗?

@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);

Go to AndroidManifest.xml , find your Sport activity and add this code 转到AndroidManifest.xml ,找到您的Sport活动并添加此代码

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

Substitute PARENT_ACTIVITY_PATH with the name of your parent activity adding also your package name (eg com.example.Categories). 用您父项活动的名称替换PARENT_ACTIVITY_PATH ,同时添加您的包名称(例如com.example.Categories)。

Going off @Mangusto. 离开@Mangusto。 After adding the parent activity path to your AndroidManifest add this line in the onCreate method of your Sport activity getSupportActionBar().setDisplayHomeAsUpEnabled(true); 将父活动路径添加到AndroidManifest后,在体育活动的onCreate方法中添加此行getSupportActionBar().setDisplayHomeAsUpEnabled(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM