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 .
Related
I have a Spinner to which I add entries statically. I know I can use an adapter and have a text view for items an so on... But that is not what I'm looking for. What I want is to tell the spinner to break down large items in multiple lines in XML. I just need to know is there any way to do that in layout file or
my ?
here is my spinner which is filled from a string-array:
<Spinner android:id="#+id/spr_my_spinner"
android:entries="#array/my_string_array"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_width="0dp"
/>
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" />
I have a spinner with a custom text view like in the code below:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:singleLine="true"
android:textSize="16sp"
android:ellipsize="end"
android:gravity="center_vertical">
</TextView>
My problem is that the Text Size of 16sp is applied to the selected item (the text from prompt) too and it's too large for the spinner (it doesn't fit the spinner) and if I change the textSize to 11sp then the items on the list will be too small. How can I change the size only for the selected item?
Well, maybe you can modify textsize in setOnItemClickListener, by the way you can simply create a button and, clicking on it, show a dialog with a list of element so you emulate spinner behavior. In this way you can customize button text size and list as you want
i need to reduce the font size and width of spinner that means i need small spinner.below i copy the code of spinner.
my code:in main.xml:
<Spinner
android:id="#+id/fromSpinner"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="-20dp"
android:prompt="#string/country_prompt"
android:entries="#array/from_spinner"/>
in strings.xml:Choose a Country
<string-array name="from_spinner">
<item>Chennai</item>
<item>Salem</item>
<item>Delhi</item>
<item>Mumbai</item>
</string-array> `
The easier way is to change the your spinner items view when you are subclassing array adapter: don't use android.R.layout.simple_spinner_item
Use
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.my_item_spinner_layout);
instead of
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.planets_array,android.R.layout.simple_spinner_item)
my_item_spinner_layout.xml look like this for exemple
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:text="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp">
</TextView>
You will need to use a custom view and inflate it using an adapter to get full control.
If you define the array in strings.xml and assign the entries you have limited control. You can have some control using HTML format in the XML itself.
For example: bolding an entry would be (this works)
<item><b>Chennai</b></item>
I don't know if this will work for the size but try it out....
<item><small>Chennai</small></item>
<item><big>Salem</big></item>
I have a custom spinner layout with an image and a text view but I noticed that depending on the manufacturers skin you cant see the text because of the color ie. white on white, black on black.
I also noticed that none of my other non-custom spinners do this and seems to change automatically so my question is how can I get the text color to change so that it can be read?
this is a non-custom spinner
ArrayAdapter<CharSequence> cAdapter;
cAdapter = ArrayAdapter.createFromResource(this, R.array.colors,android.R.layout.simple_spinner_item);
int cSpinnerDD = android.R.layout.simple_spinner_dropdown_item;
cAdapter.setDropDownViewResource(cSpinnerDD);
color.setAdapter(cAdapter);
the custom spinner I just override the view to put the images in with text
here is the layout for it
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/icon_txt"
android:paddingLeft="25dp"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Use the default text color of the current theme (stored in the resource ID android.R.attr.textColorPrimary) :
<TextView android:id="#+id/icon_txt"
android:textColor="?android:attr/textColorPrimary"
... />
I think changing your theme changes the appearance of the listview.
I was also stucked at this point but what i did was that i made a new android app project and selected blank activity (in place of empty activity) and it worked (i know that's not a good solution but it solved my issue)