Android spinner with date picker, like Google Calendar app - android

I'm trying to get a text box that looks like a spinner to activate a date picker dialog. This is done in both the Google Calendar app and the Contacts app (for birthdate) on ICS. Do I need to use a spinner, and if so how do I change it's input view to be a date picker? Or if not, how do I get a text view to have the little triangle that usually indicates a spinner?

Twaddington's comment on his answer is actually the right approach.
What you need is to create a text view and apply the style
style="#android:style/Widget.DeviceDefault.Light.Spinner"
Then you can create a click listener on the text view and use it to open a DatePickerDialog. That can be accomplished as shown here: https://stackoverflow.com/a/8127571/332738
(If you follow the example, remember to add a default constructor to DatePickerDialogFragment so that your app does not crash on rotate)

I don't know if you still need this. But in the Contacts app, it is achieved with the following:
<Button
...
style="?android:attr/spinnerStyle"
... />
This should work over all Android versions, as it is available since api level 1:
http://developer.android.com/reference/android/R.attr.html#spinnerStyle

I'm not sure if this is what you're asking, but you should be able to follow the Date Picker tutorial on the Android developer website.
Also, the DatePicker and DatePickerDialog classes might be worth a look.

I would prefer below theme for Spinner like google contacts.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:spinnerStyle">#style/AppTheme.Form.Spinner</item>
<item name="android:spinnerItemStyle">#style/AppTheme.Form.Spinner.Item</item>
</style>
<!-- Spinner Styles -->
<style name="AppTheme.Form.Spinner" parent="Widget.AppCompat.Spinner">
<item name="android:paddingRight">0dp</item>
<item name="android:paddingEnd">0dp</item>
</style>
<style name="AppTheme.Form.Spinner.Item" parent="Widget.AppCompat.EditText">
<item name="android:clickable">false</item>
</style>
</resources>

Related

Set AlertDialog View Inset via style

I use Acr.UserDialogs to create cross-platform dialogs from a Xamarin Shared/PCL project. Acr.UserDialogs contains a method to create a prompt which (in Android) is an AlertDialog whose View is set to an EditText. Unfortunately the View/EditText has no margin/padding which results in it reaching until the outer left and right limits of the dialog - which looks pretty ugly. Due to it being a library I have no ability to change how exactly the EditText or the AlertDialog are created (rather than editing the libraries code on GitHub myself but that's a way I try to avoid for now if possible). What the library supports is the possibility to pass an AndroidStyleId into the call that it uses instead of the default Android AlertDialog style (new AlertDialog.Builder(activity, passedAndroidStyleId)).
Now, my idea is to create a style that defines a custom margin/padding/inset to the View of the AlertDialog kind of as follows and pass it in.
<style name="CustomPromptDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="viewInset">10dp</item>
</style>
Problem is I can't find any resources listing which "properties" can be set in a style or how they are named, so my only idea was to ask here:
Is there any way to achieve what I'm trying to do? And if yes, how?
You can set the style like this to change the form of the Alertdialog. This the method for globel setting.
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:datePickerDialogTheme">#style/Theme.picker</item>
<item name="alertDialogTheme">#style/Theme.alert</item>
</style>
<style name="Theme.alert" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="colorAccent">#FFC107</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">#FFC107</item>
<!-- Used for the background -->
<item name="android:background">#4CAF50</item>
<item name="viewInset">10dp</item>

Adding Android styles to Appcelerator View

I'd like to add styles defined in /app/platform/android/res/values to an appcelerator Button.
<style name="textAppearanceButton" parent="#android:style/TextAppearance.Material.Widget.Button">
<item name="android:textAllCaps">false</item>
</style>
When I use this code, it will apply to all buttons - which i don't want.
Is it possible to add it on selected buttons?
At the moment this is not possible. I did create a feature request for this some time ago that you can watch to show your interest:
https://jira.appcelerator.org/browse/TIMOB-19904

How to change the timepicker style?

Hi I have a question about TimePicker in Android.
I've followed this guide to create a time picker. It works however the problem is that I want to have a time picker which has scrollable option, like in this one, rather than have you to press + or - to change the time.
I've looked around in the page and in the code and cannot understand how to change it into a scrollable picker.
what i did is added library app_compatv7
and added
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 11 theme customizations can go here. -->
</style>
and add the theme to the manifest.xml so u will get new date picker

Change Text for loading screen in ActionBar-PullToRefresh library

I have successfully implemented ActionBar-PullToRefresh in my code. Now whenever I refresh the list it shows "Loading ..." text in ActionBar.
So how to change that text in ActionBar. Do I directly change the string in the library or is there any other way to do that...
Approved approach from the samples
Source: https://github.com/chrisbanes/ActionBar-PullToRefresh/tree/master/samples
Create a theme with text overrides (e.g. ptrPullText),
that is, res/values/styles.xml:
<resources>
<style name="Theme.Holo.CustomPtrHeader" parent="android:Theme.Holo">
<item name="ptrHeaderStyle">#style/Widget.Custom.PtrHeader</item>
</style>
<style name="Widget.Custom.PtrHeader" parent="android:Widget">
<item name="ptrRefreshingText">Pulling down the internet</item>
</style>
</resources>
Apply the custom theme to your activity in AndroidManifest.xml
<activity
...
android:theme="#style/Theme.Holo.CustomPtrHeader" />
or Register you own HeaderTransformer
For the example on how to do this, please see the GridView sample.
or A little hackier way
Please note that setPullText is not on the HeaderTransformer interface, it's an instance method of DefaultHeaderTransformer:
attacher = PullToRefreshAttacher.get(this);
attacher.addRefreshableView(listView, this);
transformer = ((DefaultHeaderTransformer)attacher.getHeaderTransformer());
transformer.setRefreshingText("Pulling down the internet");

How to change style from code? Want to achieve skins

How to change a style from code?
I got a style used all across my app, for all buttons. If the user changes the skin of the app, the background of this style should change.
<style name="ActionBtn">
<item name="android:layout_width">#dimen/action_btn_width</item>
<item name="android:layout_height">#dimen/action_btn_height</item>
<item name="android:background">#drawable/btn_frame_bgstate</item>
<item name="android:padding">#dimen/action_btn_padding</item>
<item name="android:layout_margin">#dimen/action_btn_margin</item>
</style>
So far the only idea I got is to make a custom button that itself chooses its background on creation.
I have not found any good, generic way for skinning android apps yet, but if I could change styles from code, that would do the trick.
All suggestions welcome!
1) Create different themes for your skins.
2) Set those themes programatically using following code in your onCreate method.
setTheme(resid);
resid is the id of your theme.

Categories

Resources