美文网首页
android ActionBarDrawerToggle 对象

android ActionBarDrawerToggle 对象

作者: wenSome | 来源:发表于2023-07-21 17:40 被阅读0次

使用 DrawerLayout 实现侧滑菜单(抽屉菜单)时的常见用法。

   // ActionBarDrawerToggle继承自DrawerListener,
       drawer_layout.run {
           // 新建了一个ActionBarDrawerToggle对象
           val toggle = ActionBarDrawerToggle(
               this@MainActivity, // this@MainActivity等价于MainActivity.this
               this,
               toolbar, R.string.navigation_drawer_open,
               R.string.navigation_drawer_close
           )
           addDrawerListener(toggle)
           toggle.syncState()
       }

1、通过调用 toggle.syncState() 来同步状态,确保侧滑菜单的图标和状态与 DrawerLayout 的状态保持同步。

2、ActionBarDrawerToggle自带按钮图标的

3、ActionBarDrawerToggle 类是为了方便管理 DrawerLayout 的开关按钮而设计的,它提供了一个默认的按钮图标用于表示抽屉菜单的打开和关闭状态。

在调用 ActionBarDrawerToggle 构造函数时,你可以为它提供一个 Toolbar 实例,该实例将用于替换默认的 ActionBar 图标并支持导航按钮的点击事件。当侧滑菜单打开时,该按钮图标将自动更改为表示关闭状态的图标。

相关文章

网友评论

      本文标题:android ActionBarDrawerToggle 对象

      本文链接:https://www.haomeiwen.com/subject/jtmtpdtx.html