[TIMOB-19377] Android Lollipop - Preferences Activity no longer has action bar
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-08-31T02:06:38.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.0.0 |
Components | Android |
Labels | n/a |
Reporter | Shawn Lan |
Assignee | Ashraf Abu |
Created | 2015-07-31T19:21:37.000+0000 |
Updated | 2015-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>
For those who want to test this with classic app.js:-
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.
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.
I already assign it a theme with action bar, but the issue persists on Lollipop.
[~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.
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.
[~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:-
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. :)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?
[~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.
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.
[~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.
PR for fix: https://github.com/appcelerator/titanium_mobile/pull/7045
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.
[~shawnlan] Understand what you mean. Got it.