我像这样使用 ShowcaseView:
ActionItemTarget target = new ActionItemTarget(this, R.id.menu_search);
ShowcaseView sv = new ShowcaseView.Builder(this, true)
.setTarget(target)
.setContentText("Press this to search")
.setStyle(R.style.CustomShowcaseTheme)
.build();
但是当我第一次启动应用程序时,ShowcaseView 会突出显示主页按钮。当我尝试再次启动应用程序时,会显示正确的 ActionBar 项目。 我的应用程序不使用像 ActionbarSherlock 这样的兼容性库。
知道为什么会发生这种情况吗?
最佳答案
根据要求:
问题是您正在尝试检索尚不在层次结构中的 View 的 id。根据 Activity View 周期,菜单仅在onCreate
之后创建。最好的解决方案是使用 onCreateOptionsMenu
但即使在这里 R.id.menu_search
也不会返回有效的 id,因为菜单尚未创建。由于事件顺序在 API lvl 16 中发生了变化,我建议你稍微修改一下。您可以在 onCreate()
上创建一个处理程序并执行 postDelayed 可运行程序。该代码将在菜单设计完成后执行。在该可运行程序上,您可以检索 R.id.menu_search
的 View 并突出显示它。
关于android - ShowcaseView 突出显示错误的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26144849/