[英]ActionBarSherlock: how to access home button view?
I am using ActionBarSherlock and want a similiar functionality of the home button as it is known by Google Maps. 我正在使用ActionBarSherlock,并希望有类似Google地图已知的Home按钮的功能。
I already managed to open a QuickAction ( http://code.google.com/p/simple-quickactions/ ) when pressing the home button with this piece of code: 在按下带有以下代码的主页按钮时,我已经设法打开QuickAction( http://code.google.com/p/simple-quickactions/ ):
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
View anchor = findViewById(R.id.text); // how do I get the home button view here?
quickAction.show(anchor);
return true;
}
return false;
}
However I am using a simple TextView of the activity as an anchor (R.id.text). 但是,我使用活动的简单TextView作为锚点(R.id.text)。 How do I retrieve the home button view from the ActionBar there?
如何从那里的ActionBar检索主页按钮视图?
Oh, and findViewById(android.R.id.home)
or findViewById(item.getItemId())
both return null. 哦,并且
findViewById(android.R.id.home)
或findViewById(item.getItemId())
都返回null。
You cannot access the home view because it exists above the content view and in the window decoration. 您无法访问主视图,因为它位于内容视图上方和窗口装饰中。
Google uses a custom action bar on pre-Honeycomb devices which exists inside the content view. Google在内容视图内的蜂窝前设备上使用了自定义操作栏。 This is what allows them to make this custom dropdown.
这就是允许他们进行此自定义下拉菜单的原因。 On Honeycomb and newer they use a highly customized version of list navigation in the system action bar.
在Honeycomb及更高版本上,他们在系统操作栏中使用高度自定义的列表导航版本。
Since you are using ActionBarSherlock you have two options: 由于使用的是ActionBarSherlock,因此有两个选择:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.