title: how to change Action bar icon to back arrow when open a fragment
body: <p>I am trying to create an app. I want to change navigation drawer icon to back Arrow in Action Bar and when i open a fragment and go back to main activity when i click on back arrow in fragment Using the following code-</p>
  
  <pre><code>public class MainActivity extends FragmentActivity implements OnMapReadyCallback, ConnectionCallbacks, OnConnectionFailedListener,LocationListener{
   DrawerLayout mDrawerLayout;
   ListView mDrawerList;
   @SuppressWarnings("deprecation")
  ActionBarDrawerToggle mDrawerToggle;
   String mTitle="";
   private final String  TAG = this.getClass().getSimpleName();
  
      LocationRequest mLocationRequest;
      GoogleApiClient mGoogleApiClient;
  
      LatLng latLng;
      GoogleMap mMap;
      SupportMapFragment mFragment;
      Marker CurrentMarker,NearbyPlace,FindMarker;
      EditText editplace = null;
      Button findbtn = null;
      boolean firstRun = true;
      private Boolean exit = false;
  
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      //for connectivity service
      ConnectivityManager cManager = (ConnectivityManager) getSystemService(this.CONNECTIVITY_SERVICE);
      NetworkInfo nInfo = cManager.getActiveNetworkInfo();
      if (nInfo != null &amp;&amp; nInfo.isConnected()) {
          Toast.makeText(this, "Network is available ", Toast.LENGTH_SHORT).show();
  
          AdView adView = (AdView)findViewById(R.id.adView);
          AdRequest adRequest = new AdRequest.Builder()
          //.addTestDevice("abc")
          .build();
          adView.loadAd(adRequest);
      mFragment=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
      mFragment.getMapAsync(this);
  
      }
  
  
      else{
          Toast.makeText(this, "Network is not available ", Toast.LENGTH_SHORT).show();
          Fragment newFragment;
          FragmentTransaction transaction = getFragmentManager().beginTransaction();
          newFragment = new NetworkCheck();
          transaction.replace(R.id.content_frame, newFragment);
          transaction.addToBackStack(null);
          transaction.commit();
      }
  
      editplace = (EditText) findViewById(R.id.editplace);
      findbtn = (Button) findViewById(R.id.findbtn);
  
      setListnerOnWidget();
  
      mTitle = (String) getTitle();
      // Getting reference to the DrawerLayout
      mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
      mDrawerList = (ListView) findViewById(R.id.drawer_list);
  
      // Getting reference to the ActionBarDrawerToggle
      mDrawerToggle = new ActionBarDrawerToggle( this,
          mDrawerLayout,
          R.drawable.ic_drawer,
          R.string.drawer_open,
          R.string.drawer_close){
  
              /** Called when drawer is closed */
              public void onDrawerClosed(View view) {
                  getActionBar().setTitle(mTitle);
                  invalidateOptionsMenu();
              }
  
              /** Called when a drawer is opened */
              public void onDrawerOpened(View drawerView) {
                  getActionBar().setTitle("Select a menu");
                  invalidateOptionsMenu();
              }
      };
  
      // Setting DrawerToggle on DrawerLayout
      mDrawerLayout.setDrawerListener(mDrawerToggle);
      mDrawerToggle.setDrawerIndicatorEnabled(true);
  
      // Creating an ArrayAdapter to add items to the listview mDrawerList
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(
          getBaseContext(),
          R.layout.drawer_list_item ,
          getResources().getStringArray(R.array.menu)
      );
  
      mDrawerList.setAdapter(adapter);
  
      getActionBar().setHomeButtonEnabled(true);
      getActionBar().setDisplayHomeAsUpEnabled(true);
  
  
  
  
      // Setting item click listener for the listview mDrawerList
      mDrawerList.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent,
              View view,
              int position,
              long id) {
              displayView(position);
              // Updating the action bar title
              String[] menu = getResources().getStringArray(R.array.menu);
              mTitle = menu[position];
  
              mDrawerLayout.closeDrawer(mDrawerList);
  
          }
  
          private void displayView(int position) {
              // TODO Auto-generated method stub
              Fragment newFragment;
              FragmentTransaction transaction = getFragmentManager().beginTransaction();
              switch (position) {
              case 0:
  
                  newFragment = new Help();
                  transaction.replace(R.id.content_frame, newFragment);
                  transaction.addToBackStack(null);
                  transaction.commit();
                  break;
  
              case 1:
  
                  newFragment = new ContactUs();
                  transaction.replace(R.id.content_frame, newFragment);
                  transaction.addToBackStack(null);
                  transaction.commit();
                  break;
  
                case 2:
  
                  transaction.addToBackStack(null);
                  getActionBar().setTitle("IQWINER");
                  try
                  { 
                    Intent i = new Intent(Intent.ACTION_SEND);  
                    i.setType("text/plain");
                    i.putExtra(Intent.EXTRA_SUBJECT, "My application name");
                    String sAux = "\nLet me recommend you this application\n\n";
                    sAux = sAux + "https://play.google.com/store/apps/details?id=com.iqwiner\n\n";
                    i.putExtra(Intent.EXTRA_TEXT, sAux);  
                    startActivity(Intent.createChooser(i, "Choose an action"));
  
                  }
                  catch(Exception e)
                  { //e.toString();
                  } 
                  break;
  
                case 3:
                  newFragment = new Suggestion_Address();
                  transaction.replace(R.id.content_frame, newFragment);
                  transaction.addToBackStack(null);
                  transaction.commit();
                  Log.e(TAG, "Suggestion Address button is clicked");
                  break;
  
              }
  
          }
  
      });
  
  
  
  }
  
  private void setListnerOnWidget() {
      // TODO Auto-generated method stub
      OnClickListener listener = new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
  
              String location = editplace.getText().toString();
              if(location!=null &amp;&amp; !location.equals("")){
                    new GeocoderTask().execute(location); 
  
                  }
      }
      };
     findbtn.setOnClickListener(listener);
  
  }
  
  
  
  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
      super.onPostCreate(savedInstanceState);
      mDrawerToggle.syncState();
  }
  
  
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      mDrawerToggle.onConfigurationChanged(newConfig);
  }
  
  
  
  
  //for back button 
  
  @Override
  public void onBackPressed() {
  
      if(mDrawerLayout.isDrawerOpen(Gravity.START)){
          mDrawerLayout.closeDrawer(Gravity.START);
         }
      else if(getFragmentManager().getBackStackEntryCount() &gt; 1){
           super.onBackPressed(); 
      }
      else{
          if (exit){
              finish(); // finish activity
          }
          else{
              Toast.makeText(this, "Tap Back again to Exit.",
                      Toast.LENGTH_SHORT).show();
              exit = true;
              new Handler().postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      exit = false;
                  }
              }, 3 * 1000);
          }
      }
  }
  </code></pre>
  
  <p>I want to change navigation drawer icon to back arrow icon when i open a fragment and when i click on back arrow then go back to main activity from a fragment.</p>
  
  <p>Thanks</p>