从片段内访问ActionBar [英] Access the ActionBar from within a Fragment

查看:95
本文介绍了从片段内访问ActionBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从片段(android.support.v4.app.Fragment)中访问ActionBar.我正在使用Android支持库v4和v7.我没有使用Sherlock库的.

How do you access the ActionBar from within a Fragment (android.support.v4.app.Fragment). I am using the Android Support Library v4 and v7. I'm not using the Sherlock library's.

承载该片段的活动是一个ActionBarActivity.

The activity hosting the fragment is an ActionBarActivity.

我已经阅读了Android帮助部分片段,这也导致了我的getActivity (),但没有getSupportActionBar()方法.

I have read the Android help section Fragment which led me too getActivity() but there is no getSupportActionBar() method.

ActionBar actionBar = getActivity().getSupportActionBar()

推荐答案

我已经阅读了Android帮助片段Fragment,它也导致了我getActivity(),但没有getSupportActionBar()方法.

I have read the Android help section Fragment which led me too getActivity() but there is no getSupportActionBar() method.

您需要将getActivity()的结果强制转换为ActionBarActivity,在其上可以找到getSupportActionBar().

You will need to cast the result of getActivity() to be an ActionBarActivity, on which you will find getSupportActionBar().

这篇关于从片段内访问ActionBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆