【问题标题】:How can I make a Clickable Button in my Activity from the Navigation drawer?如何从导航抽屉中在我的活动中制作可点击按钮?
【发布时间】:2019-05-12 11:12:19
【问题描述】:

我正在开发一个应用程序,该应用程序具有一个用于在我的 Activity 中显示主题的导航抽屉。

导航抽屉分布在几个不同的布局中。

我的目标是为放置在 nav_header_manage_rec.xml 布局中的按钮创建一个 OnClickListener。如果你熟悉boilerplate android,它的这个区域......

导航抽屉顶部的绿色区域是我要添加按钮的地方。我尝试使用

制作一个按钮
 val themeDarkButton: ImageButton = findViewById<ImageButton>(R.id.theme_dark_button)

在导航抽屉所在的活动中,无济于事。这是一个障碍,我要添加按钮的区域位于其自己的布局中,称为 nav_header,其设置就像标准 xml 文件一样。

一定有办法做到这一点!

 themeDarkButton.setOnClickListener {


            val themeDarkText = themeSelectorView.findViewById<TextView>(R.id.theme_dark_text)

            themeDarkText.text = "It works fine."

            Log.d("TESTING", "It is working fine.")

        }

目标:当我向左滑动并点击那个小 android 头时,抽屉下方 Activity 中的 onclicklistener 应该做出响应并执行某些操作。

重要我不想从项目菜单中选择项目。我知道该怎么做。我想在绿色区域放一个按钮,然后可以单击它。

【问题讨论】:

    标签: android kotlin navigation-drawer onclicklistener android-view


    【解决方案1】:

    据我了解,您希望运行顶部菜单中的按钮 也许这会对你有所帮助

     override fun onOptionsItemSelected(item: MenuItem): Boolean {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        when (item.itemId) {
            R.id.itme1 -> {/*itme1 is your button*/
                webframe.loadUrl("https://play.google.com/store/apps/details?id=com.aradev.net")/*her my button make webview go tu url*/
            }
        }
        return true
    }
    

    【讨论】:

    • 不,抱歉。这仅适用于菜单项。我只想在菜单项上方添加一个按钮。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-26
    相关资源
    最近更新 更多