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>
Related
I am trying to achieve following layout :
I want to expand each view on click.
How do I obtain the shadow over each view?
I have tried the following drawable :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="#cacaca"
android:centerColor="#b6b6b6"
android:endColor="#e9e9e9"
/>
</shape>
<gradient
android:startColor="#6586F0"
android:centerColor="#D6D6D6"
android:endColor="#4B6CD6"
android:angle="90"/>
</item>
<item
android:left="0dp"
android:right="0dp"
android:top="5dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
<corners android:radius="20dp"/>
</shape>
</item>
</layer-list>
But it is showing following view :
Please help me to achieve the proper view.
you can achieve this by nesting multiple cardViews inside the FrameLayout.
Change the android:layout_marginTop and app:cardElevation properties to give this stack effect.
Try below code :
For Drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Drop Shadow Stack -->
<item>
<shape android:shape="rectangle">
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<solid android:color="#14000029" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<solid android:color="#14000029" />
</shape>
</item>
<item>
<shape
android:shape="rectangle">
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<solid android:color="#14000029" />
</shape>
</item>
<!-- Background -->
<item>
<shape
android:shape="rectangle">
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<solid android:color="#android:color/white"/>
</shape>
</item>
</layer-list>
Code in Layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CardViewShadowActivity"
android:layout_marginTop="30dp">
<LinearLayout
android:id="#+id/linear_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="30dp"
android:background="#drawable/custom_bg">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="30dp"
android:background="#drawable/custom_bg"
android:layout_below="#id/linear_1"
android:layout_marginTop="-20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="30dp"
android:background="#drawable/custom_bg"
android:layout_below="#id/linear_2"
android:layout_marginTop="-20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:paddingBottom="30dp"
android:background="#drawable/custom_bg"
android:layout_below="#id/linear_3"
android:layout_marginTop="-20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"/>
</LinearLayout>
</RelativeLayout>
Customize layout and drawable according to your need.
Output for above code is:
I hope this helps you
I'm trying to set a transparent circle with a stroke as the background of a TextView in android:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:background="#drawable/decibel_circle"
android:text="30 dB"
android:fontFamily="sans-serif"
android:textColor="#android:color/black"
android:textSize="70dp" />
</RelativeLayout>
And this is the shape I want to use, located in decibel-circle.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="5dp"
android:color="#F44336">
</stroke>
<solid android:color="#android:color/transparent"/>
<size
android:width="36dp"
android:height="36dp" />
<corners android:radius="12dp" />
</shape>
</selector>
The problem is that the shape is never shown, neither in the preview nor when I run my app.
What am I doing wrong?
in your decibel-circle.xml remove selector just use shape alone
Use this only
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="5dp"
android:color="#F44336">
</stroke>
<solid android:color="#android:color/transparent"/>
<size
android:width="36dp"
android:height="36dp" />
<corners android:radius="12dp" />
</shape>
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
The following is my ListView with a background. List items when pressed are showing unwanted areas at upper right and lower right corners. I want them to disappear. What can I do?
I have attached the XML code for the background here:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:right="15dp">
<shape android:shape="rectangle" >
<solid android:color="#6bb726" />
<size android:width="3dp" android:height="0dp" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle" >
<solid android:color="#aaaaaa" />
<corners
android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="15dp"
android:topLeftRadius="0.1dp"
android:topRightRadius="15dp" />
</shape>
</item>
<item android:left="5dp" android:top="2dp" android:bottom="2dp" android:right="2dp">
<shape android:shape="rectangle">
<gradient
android:type="radial"
android:centerX="150%"
android:centerY="50%"
android:startColor="#999999"
android:endColor="#eeeeee"
android:gradientRadius="100"/>
<corners
android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="12dp"
android:topLeftRadius="0.1dp"
android:topRightRadius="12dp" />
</shape>
</item>
</layer-list>
ListView layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/denko_station_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="50dp"
android:divider="#android:color/transparent"
android:dividerHeight="10dp" />
</RelativeLayout>
just add the following line in listview layout code:
android:listSelector="#android:color/transparent"
like below
<ListView
android:id="#+id/lvId"
android:layout_width="match_parent"
android:listSelector="#android:color/transparent"
android:layout_height="match_parent"/>
Set
android:listSelector="#android:color/transparent"
for your listView in xml file.
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>