How can I remove the Hamburger icon from my NavigationView when I go to another fragment and then change it to a "back" icon?
NavigationActivity.kt:
package com.example.gonzalo.proyecto_android_2018.activities
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.widget.NavigationView
import android.support.v4.view.GravityCompat
import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.widget.Toolbar
import android.view.MenuItem
import com.example.gonzalo.proyecto_android_2018.R
import com.example.gonzalo.proyecto_android_2018.fragments.*
import kotlinx.android.synthetic.main.activity_navigation.*
class NavigationActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener{
lateinit var tb:Toolbar
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_navigation)
//SETUP TOOLBAR
tb = toolbar as Toolbar
//tb.title = "LIGHT BUS"
//SETUP NAVIGATIONVIEW
setupNavigation()
setupFragment(HomeFragment())
navigation.menu.getItem(0).isChecked = true
}
private fun setupNavigation() {
//NO EXISTE LA CLASE Toogle, LO DIGO PARA NO CONFUNDIRSE CON LA VARIABLE "toogle"
val toogle = ActionBarDrawerToggle(this, drawer, tb, R.string.drawerAbierto, R.string.drawerCerrado)
toogle.isDrawerIndicatorEnabled = true //ACA LE DIGO QUE ME APAREZCA EL SIMBOLO DEL SANDWICHITO PARA PODER ABRIR Y CERRAR EL NAVIGATIONVIEW
drawer.addDrawerListener(toogle)
toogle.syncState() //ACA LE DIGO QUE SINCRONIZE EL ESTADO ABIERTO O CERRADO. EJEMPLO, DEBE CERRAR CUANDO ESTE ABIERTO Y DEBE ABRIRSE CUANDO ESTE CERRADO
navigation.setNavigationItemSelectedListener(this) //ACA LE DIGO A ESTE NAVIGATION(navigation) QUE VA A ESTAR YA AÑADIDO DENTRO DEL NAVIGATIONACTIVITY
}
private fun setupFragment(fragment: Fragment){ //Reemplaza el "R.id.frameLayout" por el id del "fragment" que se va a colocar en el "activity_navigation.xml"
supportFragmentManager.beginTransaction().replace(R.id.frameLayout, fragment).commit()
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when(item.itemId){
R.id.home -> setupFragment(HomeFragment())
R.id.mi_cuenta -> setupFragment(MiCuentaFragment())
R.id.pagos -> setupFragment(PagosFragment())
R.id.promociones -> setupFragment(PromocionesFragment())
R.id.regalo_amigo -> setupFragment(RegaloAmigoFragment())
R.id.ayuda -> setupFragment(AyudaFragment())
}
drawer.closeDrawer(GravityCompat.START) //ACA LE DIGO, DESPUES DE QUE HAYAS CAMBIADO DE FRAGMENT, CIERRA EL DRAWER
return true
}
override fun onBackPressed() {
if(drawer.isDrawerOpen(GravityCompat.START)){
drawer.closeDrawer(GravityCompat.START)
}
else{
super.onBackPressed()
}
}
}
activity_navigation.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
</FrameLayout>
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
app:itemTextColor="#009688"
app:menu="@menu/main_menu"
app:headerLayout="@layout/nav_header"
android:fitsSystemWindows="true"
android:layout_gravity = "start"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
</android.support.v4.widget.DrawerLayout>