我使用了示例
库来解释我的应用程序功能
用户。在某些时候,我需要整个动作条
变暗以present
另一个特征给用户。
I'm using the Showcase
library to explain my application feature to
the user. In some point I need to dim the whole ActionBar
to present
another feature to the user.
有关,我使用了 setAlpha(浮点NUM)
的查看
类。
所以这样做,我需要得到的实际情况来看我的动作条
For that I'm using the setAlpha(float num)
of the View
class.
And so for doing that I need to get the actual view instance of my ActionBar
顺便说一下我使用的支持-7-appcompat
库,让动作条支持
旧的系统。
And by the way I'm using the support-7-appcompat
library that gives ActionBar support for
older systems.
更新:
在此期间,我发现这个选项,如果你配置一个自定义视图,它动作条
使用添加到您:
In the meantime I found this option, if you configure a custom view and add it to you ActionBar
using:
getSupportActionBar().setCustomView(v);
然后拿到查看
的动作条
,你可以这样做:
Then to get the View
of the ActionBar
you could do:
(View) activity.getSupportActionBar().getCustomView().getParent().getParent()
但是,我认为必须有一个更简单,更容易的方式来做到这一点。
But I think that there must be a simpler and easier way to do that.
有谁知道吗?
在此先感谢。
是的。实际上,你可以认为使用该功能:
Yep. You can actually get the view by using this function:
public View getActionBarView() {
Window window = getWindow();
View v = window.getDecorView();
int resId = getResources().getIdentifier("action_bar_container", "id", "android");
return v.findViewById(resId);
}
pretty的多少这种工作方式是在动作条容器使用ID android.R.id.action_bar_container,但这个ID是不公开的。因此,我们使用则getIdentifier()来获取这个ID,然后剩下的就是简单的。
Pretty much the way this works is that the actionbar container uses the id android.R.id.action_bar_container, but this id is not public. Therefore we use getIdentifier() to retrieve this id and then the rest is simple.