Hi guys i try to implement a back button in android studio that will bring me back to my previous activity.I manage to display the button on my app but when i press the button it just don't function .There is no error in my program.
package com.example.window8.myfriend;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class design extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_design);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.images);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_image, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.home) {
Intent intent = new Intent(getApplicationContext(),Systemtime.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
返回按钮应该是 android.R.id.home & 下面的行将用于返回到父活动。
NavUtils.navigateUpFromSameTask(this);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.