getActionBar() returns null after SDK update to 5.0

吃可爱长大的小学妹 提交于 2019-12-04 05:43:41

Use getSupportActionBar() when you are using ActionBarActivity and appcompat-v7, as you appear to be doing here.

I just came across this myself. Not using AppCompat might not always be a solution, especially if you intent to use it. Therefore, if using AppCompatActivity, try inserting this in your layout.xml:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_alignParentTop="true"
    android:background="?attr/colorPrimary"/>

Then, you can use getSupportActionBar().

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