Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i add this is menu.xml file but it not show me back button in my header.please guide me

What I have tried:

<item>
android:id="@+id/action_back"
android:icon="@drawable/ic_launcher"
android:title="@string/action_back"
android:showAsAction="never"/>
Posted
Updated 30-Aug-16 4:38am
Comments
Richard MacCutchan 22-Aug-16 7:11am    
Where does this fit into your XML files, and what result(s) do you see?
wseng 30-Aug-16 10:41am    
You don't need to have menu.xml...check my answer

1 solution

This is how I solve the problem.

Add these three line after setContentView

Java
final ActionBar actionBar = getSupportActionBar();
  actionBar.setDisplayHomeAsUpEnabled(true);


And also add this code

Java
@Override
   public boolean onOptionsItemSelected(MenuItem item) {

       switch (item.getItemId()) {

           case android.R.id.home:
               onBackPressed();
               break;

           // create new file

       }
       return super.onOptionsItemSelected(item);
   }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900