我试图创建回ActionBar
按钮。我使用了以下代码,但是当我点击它时什么也没做。
这是我的清单:
<activity
android:name="com.myapps.z_music.Main_list"
android:label="@string/title_activity_main_list" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.myapps.z_music.Zmusic_Settings"
android:label="@string/title_activity_settings" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.myapps.z_music.Main_list" />
这是我的活动:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(save...);
ActionBar ac = getActionBar();
ac.setDisplayHomeAsUpEnabled(true);
}
告诉我我哪里出错了?
答案 0 :(得分:0)
您缺少parentActivityName
属性
<activity
android:name="com.myapps.z_music.Zmusic_Settings"
android:label="@string/title_activity_settings"
android:parentActivityName="com.myapps.z_music.Main_list"> // missing
您还需要
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home: // id home in respective menu.xml
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
它叫做UP导航。
http://developer.android.com/training/implementing-navigation/ancestral.html