How to customize Spinner Background in android? - android

I want to change spinner look in android and I want it to be same for all the devices. I tried to do the same but failed to do so. If I use Tag, I am not able to customize it. I am adding screenshot of image of how I want.
http://prntscr.com/gb3oh9

Try something like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#color/white" />
<stroke android:width="2px" android:color="#color/darkgray_7" />
<corners android:radius="5dp" />
</shape>
</item>
<item>
<bitmap
android:gravity="right" android:src="#drawable/arrow" />
</item>
</layer-list>
</item>
</selector>

Try following code for custom Spinner
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><layer-list>
<item><shape>
<gradient android:angle="90" android:startColor="#color/white" android:endColor="#color/appblue" />
<stroke android:width="1dp" android:color="#color/block" />
<corners android:radius="4dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape></item>
<item ><bitmap android:gravity="right|center" android:src="#drawable/drop_arrow" android:tint="#color/red" />
</item>
</layer-list></item>
</selector>

You can change background color and drop down icon like doing this way
Step1: In drawable folder make background.xml for border of spinner.
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#android:color/transparent" />
<corners android:radius="5dp" />
<stroke
android:width="1dp"
android:color="#color/darkGray" />
</shape> //edited
Step 2: For layout design
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:layout_weight=".28"
android:background="#drawable/spinner_border"
android:orientation="horizontal">
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="#android:color/transparent"
android:gravity="center"
android:layout_marginLeft="5dp"
android:spinnerMode="dropdown" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:src="#mipmap/drop" />
</RelativeLayout>
Step ex:And for dropdown arrow(styling) of the spinner you can try applying following style to your spinner using:
style="#style/SpinnerTheme"
//Spinner Style:
<style name="SpinnerTheme" parent="android:Widget.Spinner">
<item name="android:background">#drawable/backgroundg_spinner</item>
</style>
//backgorundg_spinner.xml Replace the arrow_down_gray with your arrow
<item>
<layer-list>
<item>
<shape>
<gradient android:angle="90" android:endColor="#ffffff" android:startColor="#ffffff" android:type="linear" />
<stroke android:width="0.33dp" android:color="#0fb1fa" />
<corners android:radius="0dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
</shape>
</item>
<item android:right="5dp">
<bitmap android:gravity="center_vertical|right" android:src="#drawable/arrow_down_gray" />
</item>
</layer-list>
</item>
Finally just find your particular ColorCode and append it.Here
Hope it helps...

This is how I did it (RTL Spinner):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:drawable="#drawable/ic_down_white" android:gravity="left|center" />
<item>
<shape>
<corners android:radius="4dp" />
<solid android:color="#19FFFFFF" />
</shape>
</item>
</layer-list>
</item>
</select

Related

How to make oval shape of progress in horizontal progress-bar in android

This background drawable.xml
<?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>
<corners android:radius="12dp" />
<solid android:color="#cccccc" />
</shape>
</item>
<item android:id="#android:id/progress"
>
<clip>
<shape>
<corners android:radius="12dp" />
<solid android:color="#color/colorPrimaryDark" />
</shape>
</clip>
</item>
</layer-list>
Below is my progress-bar
<ProgressBar
android:id="#+id/pb"
style="#android:style/Widget.Holo.Light.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv"
android:hapticFeedbackEnabled="true"
android:progressDrawable="#drawable/point_default_progess"
android:progress="2"
android:scaleY="0.80" />
I want to set progress shape inside progress-bar with oval shape but i am unable to set oval shape. please suggest me how to fix this issue below is my screen .
I want to make progress view in oval shape please help me in this issue.
Expected image is below
i want to set oval shape below 3 progress value .
background_drawable.xml
<?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>
<solid android:color="#777" />
<size
android:width="15dp"
android:height="15dp" />
<corners android:radius="10dp" />
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<layer-list>
<item>
<color android:color="#00000000" />
</item>
<item
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp">
<shape>
<solid android:color="#068310" />
<size
android:width="15dp"
android:height="15dp" />
<corners android:radius="10dp" />
</shape>
</item>
</layer-list>
</clip>
</item>
</layer-list>
progress-bar.xml
<ProgressBar
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="50"
android:progressDrawable="#drawable/background_drawable" />
hope it helps.
just replace <clip> with <scale>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape>
<corners android:radius="12dp" />
<solid android:color="#cccccc" />
</shape>
</item>
<item android:id="#android:id/progress">
<scale android:scaleWidth="100%">
<shape>
<corners android:radius="12dp" />
<solid android:color="#color/colorPrimaryDark" />
</shape>
</scale>
</item>

How to make custom spinner with image?

I'm trying to make a custom design for spinner but no luck, i only made it through edittext.
I want something like this.
in edittext i use drawableleft, can someone help me how can i customize my spinner?
in xml:
<EditText
android:id="#+id/etBusinessKeywor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_spinner"
android:cursorVisible="false"
android:drawableRight="#drawable/ic_keyboard_arrow_down_white_24dp"
android:hint="SERVICE"
android:padding="#dimen/_12sdp"
android:textColorHint="#color/pbr_lightgray"
android:textSize="#dimen/fontsize_title"
android:textStyle="bold" />
bg_spinner:
<item>
<shape>
<corners android:radius="3dp" />
<solid android:color="#android:color/white" />
</shape>
</item>
<item>
<shape>
<corners android:radius="3dp" />
<solid android:color="#color/colorPrimary" />
</shape>
</item>
<item android:right="50dp">
<shape>
<solid android:color="#android:color/white" />
<corners
android:bottomLeftRadius="3dp"
android:topLeftRadius="3dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="#android:color/transparent" />
</shape>
</item>
Try This,
<Spinner
android:id="#+id/spn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/selector_spinner"
android:popupBackground="#fff"
android:spinnerMode="dropdown"
/>
selector_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#000000" />
<corners
android:radius="2dp" />
</shape>
</item>
<item
android:bottom="1dip"
android:left="1dip"
android:right="1dip"
android:top="1dip">
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" >
</solid>
<corners
android:radius="2dp" />
<padding
android:right="5dp"
android:top="2dp" />
</shape>
</item>
<item>
<bitmap
android:gravity="right|center_vertical"
android:src="#drawable/ic_down_arrow" />
</item>
</layer-list>
You can find tons of answer for customizing the spinner in How to customize a Spinner in Android .Also you shouldn't use edittext as spinner.Spinners are made for choosing an option from many chooses.
try this: wrap spinner with your imageview in RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/spinner_border"
android:orientation="horizontal">
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:gravity="center"
android:spinnerMode="dropdown" />
<FrameLayout
android:layout_width="50dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#color/colorPrimary"
android:padding="3dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/dropdown_bar" />
</FrameLayout>
</RelativeLayout>
in res/drawable/spinner_border use:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#android:color/transparent" />
<corners android:radius="5dp" />
<stroke
android:width="1dp"
android:color="#color/colorPrimary" />
</shape>

dropdown item does not display by background android

I have a Dropdown in my android app.but when I set background for it, dropdown item does not display.
my .xml file:
<Spinner
android:id="#+id/spinner"
android:layout_width="254dp"
android:layout_height="42dp"
android:background="#drawable/red_color"/>
red_colot.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:top="3dp" android:left="3dp" android:right="3dp" android:bottom="3dp">
<shape>
<solid android:color="#color/red" />
<corners android:radius="4dp" />
</shape>
</item>
Hi you can resolve this with this code
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="1dp"
android:color="#color/green" />
<corners android:radius="3dp" />
</shape>
</item>
<item>
<bitmap
android:gravity="right|center"
android:src="#drawable/ic_arrow_drop_down_gray" />
</item>

Android listviewItem border color on selected

I'm going to have a listview with some items, when I select a row in a listview, it should have a border. So how can I Achieve something like this.
I try this. but it works only when I press the row
<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">
<stroke android:width="4dp" android:color="#87CEFA" />
<solid android:width="1dp" android:color="#color/greylight" />
<padding android:bottom="4dp" android:left="3dp" android:right="3dp" android:top="6dp" />
<corners android:radius="5px" />
</shape></item>
<item><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:width="1dp" android:color="#color/greylight" />
<padding android:bottom="4dp" android:left="3dp" android:right="3dp" android:top="6dp" />
</shape></item>
</selector>
and here is My row
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backColor"
android:orientation="horizontal" >
<RelativeLayout
android:id="#+id/relativeMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/list_item_selector" >
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textColor="#color/RedColor"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</LinearLayout>
Try to use android:state_focused state in one of your items in selector
<item android:state_focused="true" ><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:width="1dp" android:color="#color/greylight" />
<padding android:bottom="4dp" android:left="3dp" android:right="3dp" android:top="6dp" />
</shape></item>
try to use this code as border for your item in drawable folder :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="#android:color/transparent" />
<stroke
android:width="1px"
android:color="#61979797" />
<corners
android:bottomLeftRadius="1dp"
android:bottomRightRadius="1dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
</shape>
and use this code also for selector in drawable folder :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/border" android:state_selected="true"></item>
<item android:drawable="#android:color/transparent"></item>
</selector>
You need to use state_selected="true" in your selector.
Here's a something similar that I am using in one of my projects:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="1dp" android:color="#color/White"/>
</shape>
</item>
</selector>

Android - can't set margins for custom button

I am using Holo.Light theme and I am trying to make buttons not be transparent. I accomplished that, but now I want to add margin to the buttons and I have not been able to do that. Here is the button xml I have:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#E3E3E3" />
<corners android:radius="4dip" />
<margin
android:left="15dp"
android:right="15dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="#edeff1" />
<stroke
android:width="1dp"
android:color="#E3E3E3" />
<corners android:radius="4dip" />
<margin
android:left="15dp"
android:right="15dp" />
</shape>
</item>
</selector>
How can I add margin? My current setting doesn't render.
Thanks!
Why not add it to your button in XML?
<Button android:id="#+id/mybutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="xyz"
android:background="#drawable/custom_button"
android:layout_marginleft="15dp"
android:layout_marginleft="15dp" />

Categories

Resources