getActionBar().setDisplayHomeAsUpEnabled(true); nullpointer in preferenceActivity

后端 未结 1 1739
忘了有多久
忘了有多久 2021-01-14 13:05

I searched a lot for this issue, but didn\'t found nothing relevant.

I\' updated my app project to use api 21, now when i run preferenceactivity i ge

1条回答
  •  借酒劲吻你
    2021-01-14 13:09

    Using a PreferenceActivcity and the Theme.AppCompat.Light the method getActionBar() returns null. You should use a different style (only for API>=11).

    There is an alternative (a better alternative).

    It is suggested in the official Google doc:

    How do I use AppCompat with Preferences? You can continue to use PreferenceFragment in your ActionBarActivity when running on an API v11+ device. For devices before that, you will need to provide a normal PreferenceActivity which is not material-styled.

    Then you can use a PreferenceFragment and a ActionBarActivity for api>11. In this way you can use the Theme.AppCompat.Light theme.

    Pay attention to use getSupportActionBar() instead of getActionBar().

    0 讨论(0)
提交回复
热议问题