Como adicionar o botão Voltar no Android na Activity ActionBar
1. Add the parent activity in your manifest file In your
AndroidManifest.xml, add the parentActivityName attribute to the activity you want to add the back button to. example:
<activity android:name="com.your.package.ChildActivity" android:parentActivityName="com.your.package.ParentActivity" android:label="@string/title_activity_child" >
</activity>
2. Add a back button to your toolbar In your activity's onCreate() method, add the following code to add a back button to your action bar: // Show the Up button in the action bar. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
3. Handle the back button click Override the onOptionsItemSelected() method in your activity, and add the following code to handle the user's click on the back button: @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar's Up/Home button case android.R.id.home:
Comentários
Postar um comentário