質問

At the moment it is main activity but I want to change it to the Categories activity. 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

<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 (e.g. com.example.Categories).

他のヒント

Going off @Mangusto. After adding the parent activity path to your AndroidManifest add this line in the onCreate method of your Sport activity getSupportActionBar().setDisplayHomeAsUpEnabled(true);

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top