getActionBar() returns null in PreferenceActivity (AppCompat-v7 21)

后端 未结 4 2042
离开以前
离开以前 2020-12-09 16:12

I have implemented DoneBar (two buttons in actionbar) in PreferenceActivity as provided in v20 sdk samples, but after updating SDK and AppCompat to version 21 m

4条回答
  •  一向
    一向 (楼主)
    2020-12-09 16:31

    I managed to fix this issue by specifying custom theme for my settings activity,

    
    

    and : android:theme="@style/SettingsTheme" in manifest for activity

    actionbar is again showing on KITKAT and LOLIPOP and (have not tested it) back to api v11. I tested it and it works (with no actionbar as expected) on api 10.

    From debugging on lolipop, FEATURE_NO_TITLE was being set in PhoneWindow.java:3243 :

       if (a.getBoolean(R.styleable.Window_windowNoTitle, false)) {
            requestFeature(FEATURE_NO_TITLE);
    

    which removes FEATURE_ACTION_BAR

    [edit]

    but this action bar is not from material theme, so still its not perfect

    [edit2]

    I gave up with Headers, now I am using PreferenceFragment backport from github. Now all my actionbars are the same after upgrade to appcompact 21.

提交回复
热议问题