Search code examples
androidandroid-5.0-lollipopappcelerator-titaniumandroid-calendarandroid-datepicker

Titanium Android : calendarViewShown not working Android 5.x and later


I have been trying to the date picker in Android which works perfectly fine, My issue is with the calendarViewShown property. I need to use old style Date picker in the all the versions of android, this works as default in android 4 and lower but when we run the app on android 5 and later the default date picker shows the calendar and instead i would want use the old date picker. For which i have used the property calendarViewShown and as shown in the below pic I'm not getting the expected result.

<Alloy>
<Window class="container">
<View backgroundColor="black" height="Ti.UI.SIZE" width="Ti.UI.SIZE">
<Picker calendarViewShown="false" nativeSpinner="true" type="Ti.UI.PICKER_TYPE_DATE" datePickerMode="spinner"></Picker>
</View>
</Window>
</Alloy>

Solution

  • I finally found a fix for this issue, we have to use theme with the picker to use the defaulf date picker. Have a look at the following codes :

    **** xml code ****

    <Alloy>
        <Window id="win" title="" backgroundColor="transparent">
            <View height="100%" width="100%" backgroundColor="transparent" id="backView"></View>
            <View height="Ti.UI.SIZE" layout="vertical" backgroundColor="#f2f2f2" width="90%">
                <Label id="currentDate" top="10" color="#000" bottom="10" left="20"></Label>
                <View height="1" left="0" right="0" backgroundColor="#d9d9d9"></View>
                <View id="pickerView" height="Ti.UI.SIZE"></View>
                <Picker calendarViewShown="false" nativeSpinner="true" type="Ti.UI.PICKER_TYPE_DATE" backgroundColor="#f2f2f2" id="androidPicker" width="Ti.UI.FILL"></Picker>
                <View height="1" left="0" right="0" backgroundColor="#d9d9d9"></View>
                <View height="40dp">
                    <View height="40dp" width="50%">
                    <Label id="cancelButton" color="#000" right="20dp" onClick="closeWindow">Cancel</Label>
                    </View>
                    <View height="40dp" width="50%">
                        <Label id="doneButton" color="#000" onClick="getDatePicker">Done</Label>
                    </View>
                </View>
            </View>
        </Window>
    </Alloy>
    

    paste below styling in theme file in platfrom >> custometheme.xml

    **** theme ****

    <style name="Theme.Transparent" parent="@android:style/Theme.Holo.Light.Dialog">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">true</item>
    </style>
    

    Hope it works for others also.