Here is all of the code that I am using to create my spinner. This is what I am expecting the spinner to look like:
Instead I am just getting a spinner that does not have the drop down arrow and it is just a brown box.
<style name="spinner_style">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#drawable/gradient_spinner</item>
<item name="android:layout_margin">10dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">20dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:popupBackground">#DFFFFFFF</item>
</style>
Spinner
<Spinner
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="#+id/spinner"
android:spinnerMode="dropdown"
android:layout_alignTop="#+id/buttonWednesday"
android:layout_centerHorizontal="true"
style="#style/spinner_style"/>
Drawable
<item><layer-list>
<item><shape>
<gradient android:angle="90" android:endColor="#B3BBCC" android:startColor="#E8EBEF" android:type="linear" />
<stroke android:width="1dp" android:color="#000000" />
<corners android:radius="4dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape></item>
<item ><bitmap android:gravity="bottom|right" android:src="#drawable/spinner_arrow" />
</item>
</layer-list></item>
Related
I would like to design a simple spinner like below:
Below is my code:
sinnerBg.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false" android:state_enabled="true"
android:drawable="#android:color/black" />
<item>
<layer-list>
<item>
<shape>
<solid android:color="#ffffff" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
<item >
<bitmap android:gravity="right" android:src="#drawable/arrow_down" />
</item>
</layer-list>
</item>
</selector>
In style.xml:
<style name="spinner_style">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#drawable/spinnerBg</item>
<item name="android:layout_margin">10dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">20dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:popupBackground">#000000</item>
<item name="backgroundTint">#ffffff</item>
<item name="android:textColor">#000000</item>
</style>
Spinner in my axml file:
<Spinner
android:layout_width="64.0dp"
android:layout_height="wrap_content"
android:layout_weight="0.75"
android:ems="10"
android:spinnerMode="dropdown"
android:layout_marginRight="6.0dp"
android:id="#+id/PIC"
android:layout_marginTop="12.5dp"
style="#style/spinner_style" />
The code to populate the spinner:
ArrayAdapter<ViewModel> myAdapter = new ArrayAdapter<ViewModel>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, InfoList);
_spinner.Adapter = myAdapter;
The selected text color of my spinner is coming white which is why the spinner selected text is not displayed in my page:
What am I missing? Any help?
EDIT
This is happening because my spinner is inside linear layout which has background color white:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:background="#color/white">
I want my page to be white. That is the reason I had set white background for root linearlayout.
I managed to solve the issue. Hope it helps. Here is my solution for it:
style.xml:
<style name="spinner_style">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#drawable/gradient_spinner</item>
<item name="android:layout_marginTop">2dp</item>
</style>
gradient_spinner.xml
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<solid android:color="#ffffff" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
<item >
<bitmap android:gravity="bottom|right" android:src="#drawable/ic_arrow_down" />
</item>
</layer-list>
</item>
</selector>
I made a change here, added SetDropDownViewResource with custom layout:
ArrayAdapter<AgentViewModel> agentAdapter = new ArrayAdapter<AgentViewModel>(this, Resource.Layout.custom_spinner_item, InfoList);
agentAdapter.SetDropDownViewResource(Resource.Layout.spinner_dropDowm_item_view);
_spinner.Adapter = agentAdapter;
spinner_dropDowm_item_view.xml
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#color/white"
android:padding="10dp"
/>
And added spinner_style style to the spinner:
<Spinner
android:layout_width="64.0dp"
android:layout_weight="0.75"
android:ems="10"
android:spinnerMode="dropdown"
android:id="#+id/spinner"
android:layout_marginTop="12.5dp"
android:layout_column="1"
android:layout_columnSpan="3"
android:layout_row="0"
android:layout_columnWeight="3"
android:layout_marginRight="7.0dp"
android:layout_marginBottom="4.5dp"
style="#style/spinner_style" />
You can use
android:spinnerItemStyle
android:spinnerDropDownItemStyle
You are missing to set
textAppearanceSmallPopupMenu
<item name="android:textAppearanceSmallPopupMenu">#style/my_style</item>
Finally
<style name="my_style" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small">
<item name="android:textColor">#000000</item>
<item name="android:textSize">12sp</item>
</style>
How can I make a style file that adds borders to all buttons? All buttons already have a background image.
Create your style in file res/values/styles.xml
<style name="KeyBoardButton">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">4dp</item>
<item name="android:paddingTop">8dp</item>
<item name="android:paddingBottom">8dp</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:textColor">#555</item>
<item name="android:background">#drawable/button_border</item>
</style>
Define the border that will be used in file res/drawable/button_border.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="4dp"/>
<solid
android:color="#d5cbc6" />
<stroke
android:width="2dp"
android:color="#dedede" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="4dp"/>
<solid
android:color="#f9f9f9" />
<stroke
android:width="2dp"
android:color="#dedede" />
</shape>
</item>
Now you can use it in your layout files, as follows:
<Button android:id="#+id/my_button"
style="#style/KeyBoardButton"
android:text="1" />
I have this style on my styles.xml:
<style name="btnStyleGenoa" parent="#android:style/Widget.Button">
<item name="android:textSize">15sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:gravity">center</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">0.6</item>
<item name="android:background">#drawable/custom_btn_genoa</item>
<item name="android:padding">10dip</item>
</style>
I also have this custom_btn_genoa.xml on drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#20534e" />
<gradient android:angle="-90" android:startColor="#062d30" android:endColor="#4c898e" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#20534e" />
<solid android:color="#125156"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#20534e" />
<gradient android:angle="-90" android:startColor="#4c898e" android:endColor="#125156" />
</shape>
</item>
</selector>
Finally, i have this button:
<Button
android:text="#string/change_but"
android:textSize="15dp"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:id="#+id/change_but"
android:onClick="onChangeClicked"
style=”#style/btnStyleGenoa”
/>
The button does not use the desired style. Last line in button (style) says "attribute value expected. Any thoughts?
(Note, i found this code on a website, it's not mine)
You must replace style=”#style/btnStyleGenoa” to style="#style/btnStyleGenoa"
Working like a charm.
I have vertical progress bar, here the xml defined in drawable folder :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<gradient
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY ="0.75"
android:endColor="#ff747674"
android:angle="180"
/>
</shape>
</item>
<item android:id="#android:id/secondaryProgress">
<clip android:clipOrientation="vertical" android:gravity="bottom">
<shape>
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="180"
/>
</shape>
</clip>
</item>
<item android:id="#android:id/progress">
<clip android:clipOrientation="vertical" android:gravity="bottom">
<shape>
<gradient
android:startColor="#ffffd300"
android:centerColor="#ffffb600"
android:centerY="0.75"
android:endColor="#ffffcb00"
android:angle="180"
/>
</shape>
</clip>
</item>
</layer-list>
and this I have add to styles.xml :
<style name="Widget"></style>
<style name="Widget.ProgressBar">
<item name="android:indeterminateOnly">true</item>
<item name="android:indeterminateBehavior">repeat</item>
<item name="android:indeterminateDuration">3500</item>
<item name="android:minWidth">48dip</item>
<item name="android:maxWidth">48dip</item>
<item name="android:minHeight">48dip</item>
<item name="android:maxHeight">480dip</item>
</style>
<style name="Widget.ProgressBar.Vertical">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">#drawable/vertical_progress_bar</item>
<item name="android:indeterminateDrawable">#android:drawable/progress_indeterminate_horizontal</item>
<item name="android:minWidth">1dip</item>
<item name="android:maxWidth">12dip</item>
</style>
When I'm using it :
<ProgressBar
android:id="#+id/vertical_progressbar"
style="#style/Widget.ProgressBar.Vertical"
android:layout_width="12dip"
android:layout_height="match_parent"
android:layout_marginRight="5dp"
the "match_parent"(the parent is item(row) in custom ListView) value has no effect and set the height as minHeigh, only explicit values can set height(Exmple:"100dip"),
also I have tried to set the value in my getView() method :
itemRow.vProgressBar.setMinimumHeight(convertView.getHeight());
it dosen't help, what is wrong? please help )
I am creating a custom style for a seek bar using xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<solid android:color="#00FF00" />
<corners android:radius="0dp" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape>
<solid android:color="#FF0000" />
<corners android:radius="0dp" />
</shape>
</clip>
</item>
</layer-list>
<style name="Widget.MySeekBar" parent="android:Widget.SeekBar">
<item name="android:indeterminateOnly">false</item>
<item name="android:progressDrawable">#drawable/seek_bar_progress</item>
<item name="android:minHeight">3dp</item>
<item name="android:maxHeight">3dp</item>
<item name="android:thumb">#drawable/image_seek_bar_thumb</item>
<item name="android:thumbOffset">8dp</item>
<item name="android:focusable">true</item>
</style>
I want the background to be thinner than the progress similar to the standard jelly bean style seek bars. Is there any way to do this?
Thanks
I have used this in xml:
<SeekBar
android:id="#+id/seekID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayoutComponentTopRow"
android:layout_marginTop="1px"
android:background="#drawable/slide_bar"
android:progress="0"
android:secondaryProgress="0"
android:thumb="#drawable/bt_slider" />
It sets the background and the thumbnail too.
I hope it helps!