i am trying to build a navigation drawer and i am using a actionbardrawertoggle for this. I set the parameters and there is no errors associated with them. The only thing is that my id of my drawerlayout in activity_main.xml isn't "recognized" as a parameter. I checked the ids and they are all well. I tried to change the id to see a difference in the error but there is none. As you will see the ids are identical. I also tried to change the actionbardrawertoggle to one with toolbar because i thought maybe there was a problem with the order of parameters but nothing changed. The id's name is drawer. Do you know what i am missing? Thanks for your help
Here is my code:
//Here is MainActivity:
package zeinfederico.example.tasklead_newversion
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.system.Os.close
import android.system.Os.open
import androidx.appcompat.app.ActionBarDrawerToggle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(findViewById(R.id.toolbar))
val drawerToggle = ActionBarDrawerToggle(this, drawer , R.string.open, R.string.close)
drawer.addDrawerListener(drawerToggle)
drawerToggle.syncState()
supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
}
//Here is activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:titleTextColor="@android:color/white"
android:background="?attr/colorPrimary">
</androidx.appcompat.widget.Toolbar>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:clipToPadding="false"
app:menu="@menu/main_menu"
/>
</androidx.drawerlayout.widget.DrawerLayout>```
what is drawer
? you haven't initialized such value on Java/Kotlin side, so it is unresolved...
put this just after setContentView
and setSupportActionBar
val drawer = findViewById<DrawerLayout>(R.id.drawer)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.