好吧,当我正在做一些事情,我需要在我的应用程序中配置操作栏我从http://developer.android.com开始 ,我发现我在找什么
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);}
Run Code Online (Sandbox Code Playgroud)
加入后的当然
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
Run Code Online (Sandbox Code Playgroud)
和
@Override
public void onCreate(Bundle savedInstanceState) {
...
getActionBar().setDisplayHomeAsUpEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)
我做了所有这些但是在我的程序中我按下操作栏中的向上按钮程序崩溃,这里是logcat
09-04 12:54:02.087: E/AndroidRuntime(11033): FATAL EXCEPTION: main
09-04 12:54:02.087: E/AndroidRuntime(11033): java.lang.IllegalArgumentException: Activity LegendActivity does not have a parent activity name specified. …Run Code Online (Sandbox Code Playgroud)