Android FragmentActivity returns null in getActionBar()

*爱你&永不变心* 提交于 2019-12-04 05:19:20

You must extend ActionBarActivity instead of FragmentActivity to have Actionbar with fragments.

If you're using the v7 appcompat library, your activity should instead extend ActionBarActivity, which is a subclass of FragmentActivity (for more information, read Adding the Action Bar).

Still you can try this,

ActionBar actionBar = (ActionBarActivity)getActivity().getSupportActionBar();

More detail you can found here. http://developer.android.com/training/basics/fragments/creating.html

getActionBar() will return correct value only if you have the activity with a title bar. Make sure you have set a theme with titlebar for your activity in your manifest file.

try this in Your maifest file

android:theme="@style/AppTheme"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!