简体   繁体   English

ActionBarSherlock:如何访问主页按钮视图?

[英]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按钮的功能。

像Google Maps中的主页按钮

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,因此有两个选择:

  1. Go for the newer style navigation and customize the built-in list navigation. 选择较新的样式导航,并自定义内置列表导航。
  2. Supply a custom navigation view which mimics the home view (eg, has your app icon in it). 提供模仿主视图的自定义导航视图(例如,其中包含您的应用程序图标)。 With this custom view you will be able to provide an anchor on which the custom popup menu can be attached. 使用此自定义视图,您将能够提供一个锚,在该锚上可以附加自定义弹出菜单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM