How to remove the hamburger icon and put the back icon [Android]
up vote
1
down vote
favorite
How can I remove the Hamburger icon from my NavigationView when I go to another fragment and then change it to a "back" icon? //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I've been adding the following codes so they can replace that hamburger icon with the return icon:
navigation.menu.getItem(1).setOnMenuItemClickListener() //I miss an error
toogle.isDrawerIndicatorEnabled = false
navigation.menu.getItem(1).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
navigation.menu.getItem(2).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
navigation.menu.getItem(3).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
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()
//THERE IS NO TOGY CLASS, I SAY IT NOT TO BE CONFUSED WITH THE VARIABLE "toogle"
val toogle = ActionBarDrawerToggle(this, drawer, tb, R.string.drawerAbierto, R.string.drawerCerrado)
toogle.isDrawerIndicatorEnabled = true //HERE I SAY THAT THE SANDWICHITO SYMBOL APPEARS TO OPEN AND CLOSE THE NAVIGATIONVIEW
drawer.addDrawerListener(toogle)
toogle.syncState() //HERE I SAY TO SYNCHRONIZE THE STATE OPEN OR CLOSED. EXAMPLE, MUST CLOSE WHEN OPEN AND MUST BE OPEN WHEN CLOSED
navigation.setNavigationItemSelectedListener(this) //HERE I SAY TO THIS NAVIGATION (navigation) THAT IT WILL BE ALREADY ADDED WITHIN NAVIGATION ACTIVITY
private fun setupFragment(fragment: Fragment) //Replace the "R.id.frameLayout" with the id of the "fragment" that will be placed in the "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) //HERE I SAY, AFTER YOU HAVE CHANGED FRAGMENT, CLOSE THE 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>
android-layout android-fragments android-intent kotlin
add a comment |
up vote
1
down vote
favorite
How can I remove the Hamburger icon from my NavigationView when I go to another fragment and then change it to a "back" icon? //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I've been adding the following codes so they can replace that hamburger icon with the return icon:
navigation.menu.getItem(1).setOnMenuItemClickListener() //I miss an error
toogle.isDrawerIndicatorEnabled = false
navigation.menu.getItem(1).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
navigation.menu.getItem(2).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
navigation.menu.getItem(3).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
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()
//THERE IS NO TOGY CLASS, I SAY IT NOT TO BE CONFUSED WITH THE VARIABLE "toogle"
val toogle = ActionBarDrawerToggle(this, drawer, tb, R.string.drawerAbierto, R.string.drawerCerrado)
toogle.isDrawerIndicatorEnabled = true //HERE I SAY THAT THE SANDWICHITO SYMBOL APPEARS TO OPEN AND CLOSE THE NAVIGATIONVIEW
drawer.addDrawerListener(toogle)
toogle.syncState() //HERE I SAY TO SYNCHRONIZE THE STATE OPEN OR CLOSED. EXAMPLE, MUST CLOSE WHEN OPEN AND MUST BE OPEN WHEN CLOSED
navigation.setNavigationItemSelectedListener(this) //HERE I SAY TO THIS NAVIGATION (navigation) THAT IT WILL BE ALREADY ADDED WITHIN NAVIGATION ACTIVITY
private fun setupFragment(fragment: Fragment) //Replace the "R.id.frameLayout" with the id of the "fragment" that will be placed in the "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) //HERE I SAY, AFTER YOU HAVE CHANGED FRAGMENT, CLOSE THE 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>
android-layout android-fragments android-intent kotlin
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
How can I remove the Hamburger icon from my NavigationView when I go to another fragment and then change it to a "back" icon? //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I've been adding the following codes so they can replace that hamburger icon with the return icon:
navigation.menu.getItem(1).setOnMenuItemClickListener() //I miss an error
toogle.isDrawerIndicatorEnabled = false
navigation.menu.getItem(1).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
navigation.menu.getItem(2).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
navigation.menu.getItem(3).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
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()
//THERE IS NO TOGY CLASS, I SAY IT NOT TO BE CONFUSED WITH THE VARIABLE "toogle"
val toogle = ActionBarDrawerToggle(this, drawer, tb, R.string.drawerAbierto, R.string.drawerCerrado)
toogle.isDrawerIndicatorEnabled = true //HERE I SAY THAT THE SANDWICHITO SYMBOL APPEARS TO OPEN AND CLOSE THE NAVIGATIONVIEW
drawer.addDrawerListener(toogle)
toogle.syncState() //HERE I SAY TO SYNCHRONIZE THE STATE OPEN OR CLOSED. EXAMPLE, MUST CLOSE WHEN OPEN AND MUST BE OPEN WHEN CLOSED
navigation.setNavigationItemSelectedListener(this) //HERE I SAY TO THIS NAVIGATION (navigation) THAT IT WILL BE ALREADY ADDED WITHIN NAVIGATION ACTIVITY
private fun setupFragment(fragment: Fragment) //Replace the "R.id.frameLayout" with the id of the "fragment" that will be placed in the "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) //HERE I SAY, AFTER YOU HAVE CHANGED FRAGMENT, CLOSE THE 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>
android-layout android-fragments android-intent kotlin
How can I remove the Hamburger icon from my NavigationView when I go to another fragment and then change it to a "back" icon? //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I've been adding the following codes so they can replace that hamburger icon with the return icon:
navigation.menu.getItem(1).setOnMenuItemClickListener() //I miss an error
toogle.isDrawerIndicatorEnabled = false
navigation.menu.getItem(1).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
navigation.menu.getItem(2).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
navigation.menu.getItem(3).setOnMenuItemClickListener
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_return) //I miss an error
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()
//THERE IS NO TOGY CLASS, I SAY IT NOT TO BE CONFUSED WITH THE VARIABLE "toogle"
val toogle = ActionBarDrawerToggle(this, drawer, tb, R.string.drawerAbierto, R.string.drawerCerrado)
toogle.isDrawerIndicatorEnabled = true //HERE I SAY THAT THE SANDWICHITO SYMBOL APPEARS TO OPEN AND CLOSE THE NAVIGATIONVIEW
drawer.addDrawerListener(toogle)
toogle.syncState() //HERE I SAY TO SYNCHRONIZE THE STATE OPEN OR CLOSED. EXAMPLE, MUST CLOSE WHEN OPEN AND MUST BE OPEN WHEN CLOSED
navigation.setNavigationItemSelectedListener(this) //HERE I SAY TO THIS NAVIGATION (navigation) THAT IT WILL BE ALREADY ADDED WITHIN NAVIGATION ACTIVITY
private fun setupFragment(fragment: Fragment) //Replace the "R.id.frameLayout" with the id of the "fragment" that will be placed in the "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) //HERE I SAY, AFTER YOU HAVE CHANGED FRAGMENT, CLOSE THE 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>
android-layout android-fragments android-intent kotlin
android-layout android-fragments android-intent kotlin
edited Nov 12 at 8:24
Jayson Minard
36.2k14104170
36.2k14104170
asked Nov 9 at 19:44
Gian Franco Alexis Poma Vidal
62
62
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232342%2fhow-to-remove-the-hamburger-icon-and-put-the-back-icon-android%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown