目前它是主要活动,但我想将其更改为“类别”活动。 这是问题所在吗?
@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 :(得分: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)。
答案 1 :(得分:0)
离开@Mangusto。将父活动路径添加到AndroidManifest后,在体育活动的onCreate方法中添加此行getSupportActionBar().setDisplayHomeAsUpEnabled(true);