Normal button looks like:
Now, please let me know, How can i make a simple button same as an attached image button (i.e. button corner shape is round and also there is no gap between two buttons)
1- create shapes (with desired colors) for pressed and released states
To create the shapes I would suggest this great website the will do it for you: http://angrytools.com/android/button/
drawable\botton_shape_pressed.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/pressed_button_background"
android:endColor="#color/pressed_button_background"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
drawable\botton_shape_released.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/released_button_background"
android:endColor="#color/released_button_background"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
2- create a selector for the two shapes
drawable\botton_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/botton_shape_pressed"
android:state_pressed="true" />
<item android:drawable="#drawable/botton_shape_pressed"
android:state_selected="true" />
<item android:drawable="#drawable/botton_shape_released" />
</selector>
3- use the selector for the button
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/test"
android:textColor="#color/blue_text"
android:onClick="testOnClickListener"
android:background="#drawable/botton_selector" />
9-patch would work fine here, but I try to avoid them since it's hard for me to do them :(
You can try having a selector and using a shape for each state:
The shape would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#AAFFFFFF"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
You need to create a 9-patch drawable. In order to have no gap (margin) between the buttons you need to create the appropriate layout in XML and set the margin to 0.
look for foursquared source code and look for SegmentedButton.java file, this is the file that implement these buttons shown in the image.
Create a Nine patch drawable which is easy with draw9patch (part of android/tools) and then apply styles and themes... the tutorial at this link (Androgames.net) should get you started.
to style the text you can add this to the strings.xml
<style name="ButtonText">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ffffff</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">3dp</item>
<item name="android:textSize">30dp</item>
<item name="android:textStyle">bold</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">2</item>
</style>
and call it in the main.xml button
style="#style/ButtonText"
and an alternative method you can play with is creating in #drawable/btn_black with the following...
<?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="#343434" />
<stroke
android:width="1dp"
android:color="#171717" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#343434"
android:endColor="#171717"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#171717" />
<corners
android:radius="4dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
You can also use ImageView in your xml file and than give onClickable and onFocusable true and then create onClick event method on backend code and give the name of the method on xml , so that instead of dealing with all shape or button issues you just put the imageview there and make it act like a button.Here is sample code for you
<ImageView
android:id="#+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:onClick="testClickEvent"
android:paddingRight="8dip"
android:paddingBottom="8dip"
android:src="#drawable/testImg"/>
As I said on backend side create method with sign like this and this will do the job
public void testClickEvent(View v){}
Then implement what you wanna do in this method
button_primary.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#color/background"
android:startColor="#color/background" />
<corners android:radius="1dp" />
<stroke
android:width="2px"
android:color="#color/colorPrimary3" />
</shape>
call
style="#style/button_primary"
Related
Based on the requirement, I am trying to implement a custom spinner in my app. Please refer the below image:
What I have tried is :
<Spinner
android:layout_width="#dimen/quoteEntryDialogItemSpinnerWidth"
android:layout_height="match_parent"
style="#style/spinner_style"
/>
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/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>
In drawable/gradient_spinner.xml:
<item><layer-list>
<item><shape>
<gradient android:angle="90" android:endColor="#535353" android:centerColor="#484848" android:startColor="#323232" android:type="linear" />
<stroke android:width="1dp" android:color="#000000" />
<corners android:bottomRightRadius="4dp" android:topRightRadius="4dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item>
<item ><bitmap android:gravity="end" android:src="#drawable/spinner_arrow" />
</item>
</layer-list></item>
All I am getting is a spinner with the same background similar to the dropdown icon.
The background of both the spinner and the icon has to be different. I am unable to achieve thi particular design. Most of the other designs have same background for both the spinner and the dropdown anchor. Please help. Thanks in advance.
Try adding left to the second item wrapping the bitmap
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item><layer-list>
<item
><shape android:layout_width="wrap_content">
<gradient android:angle="90" android:endColor="#535353" android:centerColor="#484848" android:startColor="#323232" android:type="linear" />
<stroke android:width="1dp" android:color="#000000" />
<corners android:bottomRightRadius="4dp" android:topRightRadius="4dp" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
</shape></item>
<item
android:left="130dp"
>
<bitmap android:gravity="end" android:src="#drawable/spinner_arrow" />
</item>
</layer-list></item>
</selector>
That is if you still want to try to do this your way.
Another good option is to do like GAGAN suggested, which is to make a 9patch image where the arrow is of fixed size, and the left part is resizable.
In spinner tag of your xml file,
set
android:background="#drawable/ic_dropdown"
and ic_dropdown can be your png file.
I have an XML file called playnext. I added this file as a background to my button.XML include two images that is for button press and button release.I need to add border to these two images using the XML.
XML code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="#drawable/ic_remote_playnext" ></item>
<item android:state_pressed="true" android:drawable="#drawable/next_pressdown" ></item>
</selector>
Please tell me how to add a border to this? Is there is any other way to add borders to button?
make a drawable xml as selector
<?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="yoursolidcolor for state pressed" />
<stroke
android:width="1dp"
android:color="#171717" />
<corners
android:radius="3dp" />
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
</shape>
</item>
<item>
<shape>
<solid
android:color="#yoursolidcolor for default" />
<stroke
android:width="0dp"
android:color="#171717" />
<corners
android:radius="4dp" />
<padding
android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp" />
</shape>
</item>
</selector>
Then
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/youraboveselectoe"
android:textColor="#color/white"
android:text="Button"/>
you can also check on this
Is it possible to specify border in android button?
Please add the following code in drawable xml and call the this xml like using
android:background="#drawable/border"
border.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFad eDuration="#integer/short_anim_time">
<item android:drawable="#color/orange" android:state_pressed="true" />
<item android:drawable="#color/white" android:state_focused="true" />
<item android:drawable="#color/white" />
<item>
<shape>
<stroke android:width="2dp" android:color="#color/orange" />
<padding android:bottom="#dimen/gap" android:left="#dimen/gap" android:right="#dimen/gap" android:top="#dimen/gap" />
</shape>
</item>
I want to make this kind of button [same background & text] colors by using XML Styles
that's just for an example, i want to write some other texts, like: About Me
Still i am using button created by designer in Photoshop
<ImageButton
android:id="#+id/imageButton5"
android:contentDescription="AboutUs"
android:layout_width="wrap_content"
android:layout_marginTop="8dp"
android:layout_height="wrap_content"
android:layout_below="#+id/view_pager"
android:layout_centerHorizontal="true"
android:background="#drawable/aboutus" />
Note: I need this kind of button in every size and shape
I don't want to use any image in my Android App i want to make it using XML only
Copy-pasted from a recipe written by "Adrián Santalla" on androidcookbook.com:
https://www.androidcookbook.com/Recipe.seam?recipeId=3307
1. Create an XML file that represents the button states
Create an xml into drawable called 'button.xml' to name the button states:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="false"
android:drawable="#drawable/button_disabled" />
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="#drawable/button_pressed" />
<item
android:state_focused="true"
android:state_enabled="true"
android:drawable="#drawable/button_focused" />
<item
android:state_enabled="true"
android:drawable="#drawable/button_enabled" />
</selector>
2. Create an XML file that represents each button state
Create one xml file for each of the four button states. All of them should be under drawables folder. Let's follow the names set in the button.xml file.
button_enabled.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#00CCFF"
android:centerColor="#0000CC"
android:endColor="#00CCFF"
android:angle="90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<stroke
android:width="2dip"
android:color="#FFFFFF" />
<corners android:radius= "8dp" />
</shape>
button_focused.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#F7D358"
android:centerColor="#DF7401"
android:endColor="#F7D358"
android:angle="90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<stroke
android:width="2dip"
android:color="#FFFFFF" />
<corners android:radius= "8dp" />
</shape>
button_pressed.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#0000CC"
android:centerColor="#00CCFF"
android:endColor="#0000CC"
android:angle="90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<stroke
android:width="2dip"
android:color="#FFFFFF" />
<corners android:radius= "8dp" />
</shape>
button_disabled.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#F2F2F2"
android:centerColor="#A4A4A4"
android:endColor="#F2F2F2"
android:angle="90"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<stroke
android:width="2dip"
android:color="#FFFFFF" />
<corners android:radius= "8dp" />
</shape>
3. Create an XML file that represents the button style
Once you have created the files mentioned above, it's time to create your application button style. Now, you need to create a new XML file, called styles.xml (if you don't have it yet) where you can include more custom styles, into de values directory.
This file will contain the new button style of your application. You need to set your new button style features in it. Note that one of those features, the background of your new style, should be set with a reference to the button (button.xml) drawable that was created in the first step. To refer to the new button style we use the name attribute.
The example below show the content of the styles.xml file:
<resources>
<style name="button" parent="#android:style/Widget.Button">
<item name="android:gravity">center_vertical|center_horizontal</item>
<item name="android:textColor">#FFFFFFFF</item>
<item name="android:shadowColor">#FF000000</item>
<item name="android:shadowDx">0</item>
<item name="android:shadowDy">-1</item>
<item name="android:shadowRadius">0.2</item>
<item name="android:textSize">16dip</item>
<item name="android:textStyle">bold</item>
<item name="android:background">#drawable/button</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
</style>
</resources>
4. Create an XML with your own custom application theme
Finally, you need to override the default Android button style. For that, you need to create a new XML file, called themes.xml (if you don't have it yet), into the values directory and override the default Android button style.
The example below show the content of the themes.xml:
<resources>
<style name="YourApplicationTheme" parent="android:style/Theme.NoTitleBar">
<item name="android:buttonStyle">#style/button</item>
</style>
</resources>
Hope you guys can have the same luck as I had with this, when I was looking for custom buttons. Enjoy.
Have you ever tried to create the background shape for any buttons?
Check this out below:
Below is the separated image from your image of a button.
Now, put that in your ImageButton for android:src "source" like so:
android:src="#drawable/twitter"
Now, just create shape of the ImageButton to have a black shader background.
android:background="#drawable/button_shape"
and the button_shape is the xml file in drawable resource:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#505050"/>
<corners
android:radius="7dp" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp"
android:bottom="1dp"/>
<solid android:color="#505050"/>
</shape>
Just try to implement it with this. You might need to change the color value as per your requirement.
Let me know if it doesn't work.
Have a look at Styled Button it will surely help you.
There are lots examples please search on INTERNET.
eg:style
<style name="Widget.Button" parent="android:Widget">
<item name="android:background">#drawable/red_dot</item>
</style>
you can use your selector instead of red_dot
red_dot:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#f00"/>
<size android:width="55dip"
android:height="55dip"/>
</shape>
Button:
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="49dp"
style="#style/Widget.Button"
android:text="Button" />
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#ffffffff"/>
<size
android:width="#dimen/shape_circle_width"
android:height="#dimen/shape_circle_height"/>
</shape>
1.add this in your drawable
2.set as background to your button
<gradient android:startColor="#ffdd00"
android:endColor="#color/colorPrimary"
android:centerColor="#ffff" />
<corners android:radius="33dp"/>
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp"
/>
Two things you need to do, if you want to make a custom button design.
1st is:
create a xml resource file in drawable folder (Example: btn_shape_rectangle.xml)
then copy and paste the code there.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="16dp"
android:shape="rectangle">
<solid
android:color="#fff"/>
<stroke
android:width="1dp"
android:color="#000000"
/>
<corners android:radius="10dp" />
</shape>
2nd is go to your layout button where you want to implement this design. just link up it.
Example:
android:background="#drawable/btn_shape_rectangle"
You can change shape color radius what design you want can do.
Hope it will works and help you. Happy Coding
I want to develop custom spinner like line around spinner with triangle at right bottom corner.
like following image
For above fig I wrote my custom spinner like a
spinner.xml
<Spinner android:background="#drawable/spinner_background"/>
spinner_background.xml
<?xml version="1.0" encoding="UTF-8"?>
<item android:state_pressed="true"
android:drawable="#drawable/spinner_ab_pressed_new_theme_bs">
<shape>
<solid
android:color="#color/White" />
<corners android:radius="3dp" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<stroke
android:width="2dp"
android:color="#color/skyblue" />
</shape>
</item>
<!-- spinner_ab_default_new_theme_bs -> this image for corner triangle -->
<item
android:drawable="#drawable/spinner_ab_default_new_theme_bs" >
<shape>
<solid
android:color="#color/White">
</solid>
<corners android:radius="3dp" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<stroke
android:width="2dp"
android:color="#color/gray"/>
</shape>
</item>
And I got output like following image
I tried lot but not achieve my goal please anybody have solution to develop spinner.
like above first one image.
Spinner
<Spinner
android:id="#+id/To_Units"
style="#style/spinner_style" />
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_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>
gradient_spinner.xml (in drawable folder)
<?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: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>
</selector>
#drawable/spinner_arrow is your bottom right corner image
This is a simple one.
your_layout.xml
<android.support.v7.widget.AppCompatSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/spinner_background"
/>
In the drawable folder, spinner_background.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="#color/colorWhite">
</solid>
<corners android:radius="3dp" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<stroke
android:width="2dp"
android:color="#color/colorDarkGrey"/>
</shape>
</item>
<item >
<bitmap android:gravity="bottom|right"
android:src="#drawable/ic_arrow_drop_down_black_24dp" />
</item>
</layer-list></item>
</selector>
Preview:
You can achieve the following by using a single line in your spinner declaration in XML:
Just add this: style="#android:style/Widget.Holo.Light.Spinner"
This is a default generated style in android. It doesn't contain borders around it though. For that you'd better search something on google.
Hope this helps.
UPDATE:
AFter a lot of digging I got something which works well for introducing border around spinner.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="8dp"
android:top="8dp">
<shape>
<solid android:color="#android:color/white" />
<corners android:radius="4dp" />
<stroke
android:width="2dp"
android:color="#9E9E9E" />
<padding
android:bottom="16dp"
android:left="8dp"
android:right="16dp"
android:top="16dp" />
</shape>
</item>
</layer-list>
Place this in the drawable folder and use it as a background for spinner. Like this:
<RelativeLayout
android:id="#+id/speaker_relative_layout"
android:layout_width="0dp"
android:layout_height="70dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="#drawable/spinner_style"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Spinner
android:id="#+id/select_speaker_spinner"
style="#style/Widget.AppCompat.DropDownItem.Spinner"
android:layout_width="match_parent"
android:layout_height="70dp"
android:entries="#array/select_speaker_spinner_array"
android:spinnerMode="dialog" />
</RelativeLayout>
If you don't prefer to create multiple XML files, try:
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:strokeWidth="1dp"
app:strokeColor="#color/black"
app:cardCornerRadius="4dp">
<androidx.appcompat.widget.AppCompatSpinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"/>
</com.google.android.material.card.MaterialCardView>
To change the border color:
app:strokeColor="YOUR_COLOR_HERE"
To change the border's width:
app:strokeWidth="YOUR_DP_WIDTH_HERE"
There are two ways to achieve this.
1- As already proposed u can set the background of your spinner as custom 9 patch Image with all the adjustments made into it .
android:background="#drawable/btn_dropdown"
android:clickable="true"
android:dropDownVerticalOffset="-10dip"
android:dropDownHorizontalOffset="0dip"
android:gravity="center"
If you want your Spinner to show With various different background colors i would recommend making the drop down image transparent, & loading that spinner in a relative layout with your color set in.
btn _dropdown is as:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/spinner_default" />
<item
android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/spinner_default" />
<item
android:state_pressed="true"
android:drawable="#drawable/spinner_pressed" />
<item
android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/spinner_pressed" />
<item
android:state_enabled="true"
android:drawable="#drawable/spinner_default" />
<item
android:state_focused="true"
android:drawable="#drawable/spinner_pressed" />
<item
android:drawable="#drawable/spinner_default" />
</selector>
where the various states of pngwould define your various States of spinner seleti
To change only "background" (add corners, change color, ....) you can put it into FrameLayout with wanted background drawable, else you need to make nine patch background for to not lose spinner arrow. Spinner background is transparent.
You could design a simple nine-patch png image and use it as the background of spinner. Using GIMP you can put both border and right triangle in image.
It's super easy you can just add this to your Adapter -> getDropDownView
getDropDownView:
convertView.setBackground(getContext().getResources().getDrawable(R.drawable.bg_spinner_dropdown));
bg_spinner_dropdown:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/white" />
<corners
android:bottomLeftRadius=enter code here"25dp"
android:bottomRightRadius="25dp"
android:topLeftRadius="25dp"
android:topRightRadius="25dp" />
</shape>
i have buttons with rounded corners, how to make them looks like this :
do i need to define my own style? I don't want to change my code, only XML resources, if it possible how to apply this(border radius = 0) style to my buttons?
http://android-holo-colors.com/
This service generate Holo-styles for checked components(button is your case) and then you can download zip with xml's.
Use it to fast&easy implement, or code samples.
I think the only way for you to get what you want it to write XML to make it possible.
In the drawable folder, create an xml file that will represent the shape of your button.
for example
<?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="#ff00ff" />
<stroke
android:width="1dp"
android:color="#20f8f6" />
<corners
android:radius="6dp" /> // set to 0 or erase it for sharp corners
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#ff00ff"
android:endColor="#992f2f"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#992f2f" />
<corners
android:radius="6dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
then you need to create a style in your styles.xml file
<resources>
<style name="button_text" >
<item name="android:layout_width" >fill_parent</item>
<item name="android:layout_height" >wrap_content</item>
<item name="android:textColor" >#ffffff</item>
<item name="android:gravity" >center</item>
<item name="android:layout_margin" >3dp</item>
<item name="android:textSize" >30dp</item>
<item name="android:textStyle" >bold</item>
<item name="android:shadowColor" >#000000</item>
<item name="android:shadowDx" >1</item>
<item name="android:shadowDy" >1</item>
<item name="android:shadowRadius" >2</item>
</style>
</resources>
and when you declare your button in the xml
<Button
android:background="#drawable/red_button"
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Styled Button"
style="#style/button_text" />
Check out this github post here.
Mainly check out the library provided there and added to that source code.
SnapShot:
add xml(example.xml) in folder drawable:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:topLeftRadius="4dip"
android:topRightRadius="4dip"
android:bottomLeftRadius="4dip"
android:bottomRightRadius="4dip"/>
<solid android:color="#1FC1BA"/>
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle">
<corners android:topLeftRadius="4dip"
android:topRightRadius="4dip"
android:bottomLeftRadius="4dip"
android:bottomRightRadius="4dip"/>
<solid android:color="#26262C"/>
</shape>
</item>
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:topLeftRadius="4dip"
android:topRightRadius="4dip"
android:bottomLeftRadius="4dip"
android:bottomRightRadius="4dip"/>
<solid android:color="#1B978F"/>
</shape>
</item>
</selector>
on your folder layout(activity_main.xml) in the button
android:background="#drawable/example"
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="exampleText"
android:layout_gravity="center"
android:background="#drawable/example"
android:textColor="#ffffffff" />
I think below code is exactly what you are looking for.
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="#32a5cf"
android:endColor="#32a5cf"
android:angle="270" />
<stroke
android:width="7dp"
android:color="#9032a5cf"
/>
<corners
android:radius="6dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>