Spinner drop down popup position changes in Nexus 5 (android 5.0) - android

I am using a Spinner in my app. I used the basic spinner and this is my code:`
android:layout_width="match_parent"
android:layout_height="match_parent"
style="#style/SpinnerSpinnerTheme"
android:spinnerMode="dropdown"
android:layout_gravity="center_vertical"
android:id="#+id/hj_order_date_spinner"
/>`
and this is how i instantiated in my activity
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.hj_spinner_items,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dateSpinner.setPrompt("Sort By");
dateSpinner.setAdapter(adapter);
This works fine in android 4.4.4 but on Nexus 5(using Lollipop) the drop down list/Popup changes it's position and hides the "Sort By" bar or the original spinner.
Can anyone provide any insight as to what might be the issue?

You can specify whether the spinner drop-down should overlap the anchor by using the android:overlapAnchor attribute. When using the Material spinner style, this attribute defaults to true.
<Spinner
...
android:overlapAnchor="false" />

Related

Android spinner full screen view

I have a form in a DialogFragment that includes a spinner. I don't think I can port the spinner options out to a new activity (e.g. customisable ListView etc.) as it will close the DialogFragment, so I'm using the spinner embedded into the DialogFragment (screenshot 1). There is nothing unusual about how I'm populating the spinner with an ArrayList and adapter.
<Spinner
android:id="#+id/breedingcodes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip" />
Functionally it works fine and the spinner options appear and are selectable, but looks terrible as it only uses half the screen (see screenshot 2), anchored to the position of the spinner in the DialogFragment. Is there anyway to force it to use the full screen, as in the 3rd screenshot with Breeding evidence title? I've tried fiddling with layout_height="match_parent" etc. - no joy.
App is developed for min SDK_10, compiled for SDK_23, build tools 23.0.3.
You can either create your own dialog and style it as you want, or just use
android:spinnerMode="dialog"
as attribute in spinner. See docs here
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
you could try the above in your program to get fullscreen spinner :)

Android Appcompat v21 - use old spinner style

I am using appcompat v21 in a project, but I do not like the new spinner it comes with by default. This new spinner comes only with a small downward-facing arrow that indicates it presence. I would prefer the old spinner used in 4.x versions of android which come with an EditText-like feature underlining the widget's content and an arrow in the bottom right corner.
How can I achieve this spinner style while still using appcompat v21?
The udesired spinner style:
photo of undesired spinner:
photo of desired spinner:
You can simply set the Style of the Spinner to Widget.Holo.Light.Spinner
Example
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#android:style/Widget.Holo.Light.Spinner" />
This will give you the old Spinner-Style back though there are two drawbacks:
This solution only works with API-Level 14 and up (no that big of a deal)
The appearance of the DropDown Popup-Window is managed by the "framework" - this means on pre Lollipop devices the Popup-Window will appear below the Spinner. Starting with Lollipop it'll be above the Spinner (afaik there's no way to change this). With regard to this see the following comparison (on the left pre Lollipop)
If you wish to customize the rows of the DropDown you can do so by calling setDropDownViewResource(int) on the adapter of the Spinner with the reference to your own layout.
<Spinner
android:id="#+id/spinner_nav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:overlapAnchor="false"
style="#style/Platform.Widget.AppCompat.Spinner"/>

MvvmCross Custom Spinner keep default appearance

I have a custom spinner in my Xamarin Android app using MvvmCross. The only reason I'm using custom is because the model holds a class and I want the spinner to populate the values with a property on that class. However, the appearance of the drop down doesn't look like the rest of my app. It's missing radio buttons on the right and the spacing is off. How do I make this custom spinner look just like the rest?
<Mvx.MvxSpinner
style="#style/spinner_input"
local:MvxItemTemplate="#layout/item_spinner"
local:MvxDropDownItemTemplate="#layout/item_spinnerdropdown"
local:MvxBind="ItemsSource ProductCategoryOptions; SelectedItem SelectedProductCategory" />
Item_Spinner.axml - this part seems to be just right, the appearance of the drop down once a value is selected looks just like others.
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:text="Test"
local:MvxBind="Text Caption" />
Item_SpinnerDropDown.axml - I think this is the file that is wrong. The appearance of the drop-down doesn't match.
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:text="Test"
local:MvxBind="Text Caption" />
Checkable spinners and also supporting activated state indicators is something we've recently worked on within MvvmCross - for example, see this issue and associated commits https://github.com/MvvmCross/MvvmCross/issues/481
To make an MvxSpinner support the default styles then you should be able to simply specify no local:MvxItemTemplate and no local:MvxDropDownItemTemplate - in this case then the spinner uses resources of:
global::Android.Resource.Layout.SimpleDropDownItem1Line
global::Android.Resource.Layout.SimpleSpinnerDropDownItem
This will just use the standard Android layout templates, but will rely on your list item ToString() implementations, rather than using the Caption properties.
This is similar to what the spinner and adapter use within a "normal" Android app - e.g. see http://developer.android.com/guide/topics/ui/controls/spinner.html
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
If you instead wanted to write your own spinner layouts and to base them on the Android layouts then it's probably easiest to look into the Android source to find the original layouts - e.g. looking at: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4_r1/frameworks/base/core/res/res/layout/simple_spinner_dropdown_item.xml/
One small advanced warning here is that the standard MvvmCross listitem will wrap these displayed list items in a framelayout before using it. This won't have an effect on many layouts - but might effect some. If it effects your's then you may need to write your own custom list item view (based on https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Binding.Droid/Views/MvxBaseListItemView.cs)
One final note on this - please note that https://github.com/MvvmCross/MvvmCross/issues/481 is still open, plus there is a query on the framelayout wrapping of list items in https://github.com/MvvmCross/MvvmCross/issues/539 - so please do be aware that changes and updates may happen in this area - releases in the near future may change the default appearance here.
The following works for Item_SpinnerDropDown.axml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxBind="Text Caption" />

Custom spinner like android 4.0

I try to make custom spinner looks like in android 4.0, but I dont know how to replase sprinner dropdown selection list. Any help is welcome.
I get resource files from android 4.0 sdk, but dopdown selection list does not change.
<Spinner
android:id="#+id/update_frequency_spinner"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:spinnerMode="dropdown"
android:background="#drawable/spinner_background_holo_light"
android:dropDownSelector="#drawable/list_selector_holo_light"
android:popupBackground="#drawable/menu_dropdown_panel_holo_light">
</Spinner>
This How to customize style from spinner dropdown CHOICES? may answer your question.
You could also look into using HoloEverywhere if you want a holo-themed app for pre holo devices https://github.com/ChristopheVersieux/HoloEverywhere

How to increase the clickable width of an Android spinner?

I have a Spinner which displays single digit numbers (1-6).
When I test on a phone, it's virtually impossible to click on a number because they are so narrow (font size is 12sp) and the only area which appears to be clickable is the text itself.
Ideally I'd like the user to be able click on a greater width on the Spinner drop down than just the text. I've tried padding with spaces but these are suppressed, and I've tried using PaddingLeft/Right but again there's no difference.
Here is the Spinner
<Spinner
android:id="#+id/spinner_period1"
android:layout_toRightOf="#id/spinner_weekday1"
android:layout_below="#id/col1day"
android:layout_height="wrap_content"
android:prompt="#string/enterperiod"
android:layout_width="80dp"
android:entries="#array/periodlist"
android:layout_marginRight="340dp"
android:layout_marginBottom="20dip"
/>
Note that I also set the Spinner text attributes using:
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textview"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="12sp"
android:textColor="#768766"
/>
Any ideas? Thanks in advance
Mark
Try making the TextView wider in the android:layout_width attribute.
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textview"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textSize="12sp"
android:textColor="#768766"
/>
That could possibly fix your issue or make it better at least.
Try setting your TextView layout width to some arbitrary value rather than "wrap_content". That should make the whole thing clickable, as opposed to just the wrapped content.
Just adding some padding to the spinner helped me fix this issue.
<Spinner
android:id="#+id/spinner"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:padding="25dp"
android:scrollbarSize="20dp" />
Way 1:
Display the spinner's options as a dropdown by using android:spinnerMode. Therefore have a look at the API (Android API Spinner). Or play around with android:dropDownWidth.
Way 2 (I used it in an APP but at the moment I have no access to the code):
Maybe you could set another layout while populating your spinner with text - instead of assigning the values in the XML.
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
It's copied from the following link Android Spinner. Maybe you could use one of the layout templates of android.R .

Categories

Resources