2

我有一个导航抽屉,它与抽屉图标一起工作非常好,但是,如果我从导航抽屉活动移动到我的任何片段,也会显示后退箭头,但是单击后退箭头导航抽屉打开,我只想设置我的单击后退按钮而不是打开抽屉时的操作。请帮助我纠正这个问题。

我的抽屉活动代码如下

toggle?.setDrawerIndicatorEnabled(false);

    drawer_layout.addDrawerListener(toggle!!)
    toggle!!.syncState()


    val header = (findViewById<NavigationView>(R.id.nav_view)).getHeaderView(0)


    toggle!!.isDrawerIndicatorEnabled = false


    toggle!!.setHomeAsUpIndicator(R.drawable.ic_profile_icon)

    usernameTv = header.findViewById(R.id.username_tv)
    profileImage = header.findViewById(R.id.profile_image_user)
    userDesigTv = header.findViewById(R.id.user_designation_tv)
    pointsTv = header.findViewById(R.id.points_tv)
    userPhotoImv = header.findViewById(R.id.profile_image)
    headerLayout = header.findViewById(R.id.header_layout_profile_edit)
    mainWidgetBottomMenuLayout = findViewById(R.id.main_widget)
    addProductTv = findViewById(R.id.add_products_tv);
    createJobTv = findViewById(R.id.create_job_tv);
    createPostTv = findViewById(R.id.create_post_tv);
    closeBtn = findViewById(R.id.close_btn);

    bottomNavigationView = findViewById(R.id.navigation)

    drawer = findViewById<DrawerLayout>(R.id.drawer_layout)

    navigationView = findViewById(R.id.nav_view)


    toggle?.setToolbarNavigationClickListener {
        if (drawer!!.isDrawerOpen(GravityCompat.START)) {
            drawer!!.closeDrawer(GravityCompat.START)
        } else {
            drawer!!.openDrawer(GravityCompat.START)
        }

    }
    navigationView?.setNavigationItemSelectedListener(this)

    loginSession =
        Session(
            this
        )
    val isloggedin = loginSession!!.isLoggedIn


    addProductTv?.setOnClickListener()
    {

    }

    createJobTv?.setOnClickListener()
    {
        val fragmentTransaction1 = supportFragmentManager.beginTransaction()
        fragmentTransaction1.replace(R.id.container, JobPostFragment())
            .addToBackStack(null)
        fragmentTransaction1.commit()
        closeBottomSheet()
    }

    createPostTv?.setOnClickListener()
    {

    }

    closeBtn?.setOnClickListener()
    {
        closeBottomSheet()
    }

    val fragmentTransaction1 = supportFragmentManager.beginTransaction()
    fragmentTransaction1.replace(R.id.container, FeedsViewFragment())
        .addToBackStack(null)
    fragmentTransaction1.commit()



    viewmodel = ViewModelProviders.of(this, factory).get(LoginViewModel::class.java)

    viewmodel?.getLoggedInUser()?.observe(this, Observer { it ->
        setData(it)
    })


    if (isloggedin && loginSession!!.loginDetails.get(Constants.USERTYPE).equals(Constants.COMPANY)) {
        populateMenuForCompanies()
    } else if (isloggedin && loginSession!!.loginDetails.get(Constants.USERTYPE).equals(
            Constants.INDIVIDUAL
        )
    ) {
        populateMenuForIndividual()
    }

在我的片段中

覆盖乐趣 onViewCreated(view: View, savedInstanceState: Bundle?) {

    (activity as AppCompatActivity).supportActionBar!!.setDisplayHomeAsUpEnabled(true)
    (activity as AppCompatActivity).supportActionBar!!.setDisplayShowHomeEnabled(true)

    super.onViewCreated(view, savedInstanceState)
}

请让我知道如何在单击后退箭头而不是打开导航抽屉时返回上一个片段。

任何帮助将非常感激

4

0 回答 0