Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19377] Android Lollipop - Preferences Activity no longer has action bar

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2015-08-31T02:06:38.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.0.0
ComponentsAndroid
Labelsn/a
ReporterShawn Lan
AssigneeAshraf Abu
Created2015-07-31T19:21:37.000+0000
Updated2015-09-03T18:22:55.000+0000

Description

Upgraded my app to SDK 4.0.0+. I noticed that the preferences activity no longer has the action bar (title bar). In previous version it does. Create a default Alloy project with the following: index.xml
<Alloy>
	<Window />
</Alloy>
index.js
$.index.open();
Ti.UI.Android.openPreferences();
preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="TITLE">
    <CheckBoxPreference
        android:key="key1"
        android:title="this is key 1"
        android:summary="key 1 summary"
        android:defaultValue="false" />
    <CheckBoxPreference
        android:key="key2"
        android:title="this is key 2"
        android:summary="key 2 summary"
        android:defaultValue="false" />
</PreferenceScreen>

Comments

  1. Ashraf Abu 2015-08-19

    For those who want to test this with classic app.js:-
       var win = Ti.UI.createWindow({backgroundColor: 'white'});
       var button = Ti.UI.createButton({
         title:    'Click to Open Preferences'
       });
       button.addEventListener('click', function() {
         Ti.UI.Android.openPreferences();
       });
       win.add(button);
       win.open();
       
  2. Ashraf Abu 2015-08-19

    PR: https://github.com/appcelerator/titanium_mobile/pull/7045 Run test steps with code above and an XML file as mention in original comment. Please run tests on both Android Lollipop and a version below Android Lollipop.
  3. Ashraf Abu 2015-08-20

    Workaround if you want to implement this now: If you need to use it now, take a look at http://docs.appcelerator.com/platform/latest/#!/guide/Android_Themes-section-34636181_AndroidThemes-OverrideanActivityTheme All you need to do is implement a theme for TiPreferencesActivity class. One for a "values" and another for "values-v21". Take a look at the PR https://github.com/appcelerator/titanium_mobile/pull/7045/files if you want to implement it this way.
  4. Shawn Lan 2015-08-20

    I already assign it a theme with action bar, but the issue persists on Lollipop.
       <activity
                           android:configChanges="keyboardHidden|orientation|screenSize"
                           android:name="ti.modules.titanium.ui.android.TiPreferencesActivity"
                           android:screenOrientation="portrait" android:theme="@style/Theme.AppCompat.Light"/>
       
  5. Ashraf Abu 2015-08-20

    [~shawnlan] You would need 2 Themes. Theme.AppCompat for anything less than Lollipop and Theme.Material for Lollipop and above. Theme.AppCompat does not provide an action bar on Lollipop. Theme.Material does.
  6. Shawn Lan 2015-08-20

    Theme.AppCompat does provide action bar. Please take a look at Android's doc and [here](https://docs.appcelerator.com/platform/latest/#!/guide/Android_Themes-section-34636181_AndroidThemes-MaterialTheme) All my activities use Theme.AppCompat. They all show an action bar, except the preferences activity. Test it yourself.
  7. Ashraf Abu 2015-08-21

    [~shawnlan], you are almost there. Here's what you need to do exactly:- We are going to use a new theme for the activity. The theme will be different based on what version of android we are using. In the tiapp.xml write this:-
           <android xmlns:android="http://schemas.android.com/apk/res/android">
               <manifest>
                   <application>
                   		<activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity" android:configChanges="screenSize"
       						android:theme="@style/Theme.TiPreferences" />
       	     </application>
               </manifest>
           </android>
       
    Then, we need to create a folder in these path, /platform/android/res/values and /platform/android/res/values-v21 In /platform/android/res/values-v21, put this file: https://github.com/ashcoding/titanium_mobile/blob/TIMOB-19377/android/modules/ui/res/values-v21/styles.xml In '/platform/android/res/values', put this file: https://github.com/ashcoding/titanium_mobile/blob/TIMOB-19377/android/modules/ui/res/values/styles.xml I also made a repo here: https://github.com/ashcoding/TIMOB-19377_Example that you can take a look. On the logic behind this:- Appcompat only adds an action bar to activities that derive from ActionBarActivity. PreferenceActivity does not subclass ActionBarActivity. This should work. :)
  8. Shawn Lan 2015-08-21

    Your workaround only works in Lollipop. On Android 4 and below it is still not showing action bar. Maybe you need to switch to preferencefragment?
  9. Ashraf Abu 2015-08-24

    [~shawnlan] That might be a good idea to switch to a preferencefragment. Anyway, there was a missing style for v14. https://github.com/ashcoding/TIMOB-19377_Example/tree/master/platform/android/res/values-v14 I have updated the code. It should now have the actionbar for below lollipop. Feel free to style it more. :) Let me know if it solves this for you for now.
  10. Shawn Lan 2015-08-24

    Yes it works for now, but since my app use AppCompat everywhere else, the preference activity with Theme.Holo does look different. Still prefer this to be fixed so that I can use just AppCompat, not only for look consistency but also that I don't need to have these extra style. Thanks.
  11. Ashraf Abu 2015-08-25

    [~shawnlan] You could actually customise the theme to make it look like how you want it. And that includes making it look similar to how AppCompat does it. Here's how, https://developer.android.com/training/basics/actionbar/styling.html For reference, I updated the v14 style folder, https://github.com/ashcoding/TIMOB-19377_Example/blob/master/platform/android/res/values-v14/styles.xml Hope this helps.
  12. Ashraf Abu 2015-08-25

    PR for fix: https://github.com/appcelerator/titanium_mobile/pull/7045
  13. Shawn Lan 2015-08-25

    1. The window just looks similar to, but not exactly the same as how AppCompat does it. 2. The child elements (checkboxes, on/off buttons, etc.) still look inconsistent. It's too much work to style everything and make them look like AppCompat. Your solution can be a temporary workaround, but shouldn't be a permanent fix. Thanks.
  14. Ashraf Abu 2015-08-26

    [~shawnlan] Understand what you mean. Got it.
  15. Ashraf Abu 2015-08-31

  16. Lokesh Choudhary 2015-09-03

JSON Source