【问题标题】:Change icon in Navigation Drawer on the fly即时更改导航抽屉中的图标
【发布时间】:2014-04-15 06:41:07
【问题描述】:

我目前正在尝试在发生某些事件时更改导航抽屉中的图标。可能吗??我的意思是我改变了图标 - 没问题:

    mDrawerToggle = new ActionBarDrawerToggle(
            this,                  
            mDrawerLayout,         
            R.drawable.actionbar_settings,  /* my icon - all Ok! */
            R.string.text1,  
            R.string.text2  
    ) {};

我的意思是,如果某个事件触发并且我想在另一个事件上更改此图标,该怎么办?如果我重复代码但使用另一个图标 - 没有成功。

    mDrawerToggle = new ActionBarDrawerToggle(
            this,                  
            mDrawerLayout,         
            R.drawable.new_icon_image,  /* bad news - nothing changes */
            R.string.text1,  
            R.string.text2  
    ) {};

非常感谢!

【问题讨论】:

    标签: android navigation navigation-drawer drawer


    【解决方案1】:

    有可能吗?

    是的,但您需要致电DrawerLayout.setDrawerListenerActionBarDrawerToggle.syncState 来更新指标并确保它已同步。

    这是一个例子:

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.drawable.new_icon_image, R.string.text1, R.string.text2);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多