This question already has answers here:
Android button background is taking the primary color
(6 answers)
Closed 9 months ago.
I am making a rounded and bordered button. But I am getting button with only primary color in the theme.
Here is my code in circular button drawable file:-
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/green" />
<corners android:radius="50dp" />
<stroke
android:width="10dp"
android:color="#color/red_primary" />
</shape>
here is my button code:-
<Button
android:id="#+id/feedback_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginHorizontal="5dp"
android:layout_weight="1"
android:padding="10dp"
android:background="#drawable/circular_button"
android:text="#string/send_feedback"
android:textColor="#color/white" />
also add app:backgroundTint="#null" in Button tag.
you can use bewlo code for rounded and bordered button
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/BlueDark"/>
<stroke android:width="3dp" android:color="#color/White" />
<corners android:bottomRightRadius="30dp"
android:topRightRadius="30dp"
android:topLeftRadius="30dp"
android:bottomLeftRadius="30dp"/>
<padding android:left="0dp" android:top="0dp"
android:right="0dp" android:bottom="0dp" />
</shape>
Also YOU can set boder wedith with bewlo line
<stroke android:width="3dp" android:color="#color/White" />
Related
How to add a shadow border on 4 sides of an edit text as shown in the image? Applied below code but it creates a shadow on single side only.
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FFBDBDBD"
android:centerColor="#65FFFFFF"
android:endColor="#00FFFFFF"
/>
<stroke
android:width="1dp"
android:color="#C3C3C3" />
<corners
android:radius="5dp" />
</shape>
You can use elevation like :-
android:elevation="5dp"
elevation worked as Z-index.
You can try adding width and color inside the shape tag.
It will look like this:
<stroke android:width="3dp" android:color="#bfafb2"/>
First create this background drawable with a rectangle, round corner and a stroke in grey. Called background_drawable.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff"/>
<corners android:radius="5dp" />
<stroke android:width="1dp"
android:color="#C3C3C3"/>
</shape>
After that you set this as android:background="" in your LinearLayout and EditText, both widgets have android:elevation="2dp" for it's shadow on each sites matching the stroke of the rectangle. Here is your layout called activity_main.xml:
<LinearLayout
android:layout_width="200dp"
android:layout_height="100dp"
android:elevation="2dp"
android:id="#+id/linear_layout"
android:background="#drawable/background_drawable"
android:layout_centerInParent="true"
android:orientation="horizontal" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="#+id/edit_text"
android:elevation="2dp"
android:layout_marginTop="10dp"
android:background="#drawable/background_drawable"
android:layout_below="#+id/linear_layout"
android:layout_centerHorizontal="true"
android:padding="10dp"/>
The final result will look like this image.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CABBBBBB"/>
<corners android:radius="2dp" />
</shape>
</item>
<item
android:left="2dp"
android:right="2dp"
android:top="2dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="2dp" />
</shape>
</item>
This question already has answers here:
How to change shape color dynamically?
(14 answers)
Closed 4 years ago.
I have buttons in my app that have a drawable in background:
<Button
android:id="#+id/loginbutton"
android:text="#string/login"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:layout_width="135dp"
android:layout_height="30dp"
android:background="#drawable/buttonshape"
android:layout_centerHorizontal="true"
android:layout_below="#+id/til"
android:layout_marginTop="50dp"
/>
The drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="30dp"
/>
<solid
android:color="#color/colorPrimary"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
If I do this:
loginButton.setBackgroundColor(Color.parseColor(getBgColor()));
Not only the color, but the entire shape of the button is changed, so no rounded corners, etc. How can I change only the color of the background, keeping the rest of things of my drawable?
Thank you.
Have you tried something like this:
button.setBackgroundTintList(ContextCompat.getColorStateList(context, R.color.blue));
Hello I am designing this page in android (style only)
.
First 3 buttons has been designed by taking the reference from this.
But DONATE NOW button which I have designed is become transparent like this
as well as click event (statepreseed = "true")is also transparent like
.
and here is my code of background for DONATE NOW button
<?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="0dp" />
<solid android:color="#33e7d283"></solid>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<stroke
android:width="4dp"
android:color="#00e9ca30"
/>
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<corners
android:radius="0dp"
/>
<gradient
android:angle="225"
android:centerX="23%"
android:centerColor="#33f4c40e"
android:startColor="#ffdab605"
android:endColor="#ffdab605"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
</shape>
</item>
</selector>
If any one is having the solution.please help
You are using ARGB instead of RGB. Because of this you are creating image with transparent background.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="0dp" />
<gradient
android:angle="225"
android:centerColor="#e7d283"
android:centerX="23%"
android:endColor="#ffdab605"
android:startColor="#ffdab605"
android:type="linear" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
</shape>
Using e7d283 or ffe7d283 color-code instead of 33e7d283 might solve your problem for yellow image background.
Using 33 as alpha means you are giving only 20% opacity to your center color. That is the reason you can see background color in middle of your image.
Here you go..
Your button element should look like below.
<Button
android:id="#+id/angry_btn"
android:text="Button"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="270dp"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#474747"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="3"
/>
ButtonShape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="65%"
android:centerColor="#F5FAF9"
android:startColor="#F39C12"
android:endColor="##F39C12"
android:type="linear"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#878787"
/>
</shape>
Output will look like below.
Good afternoon,
I am doing an app who needs 3 buttons aligned under the TabLayout, like in the picture below :
I do not know what is the best way to do them, because each one has different borders.
Anyone can help me ?
Thank you !
I finally did it :
buttons.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:layout_marginLeft="18sp"
android:layout_marginRight="18sp">
<Button
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="31sp"
android:id="#+id/one"
android:text="ONE"
android:textColor="#color/red"
android:layout_weight="1"
android:background="#drawable/button_shape_one" />
<Button
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="31sp"
android:id="#+id/two"
android:text="TWO"
android:textColor="#color/red"
android:layout_weight="1"
android:background="#drawable/button_shape_two"/>
<Button
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="31sp"
android:id="#+id/three"
android:text="THREE"
android:textColor="#color/red"
android:layout_weight="1"
android:background="#drawable/button_shape_three"/>
</LinearLayout>
button_shape_one.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/transparent"/>
<stroke android:width="1dp"
android:color="#color/red"
/>
<corners android:bottomRightRadius="0dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="0dp"/>
</shape>
button_shape_two.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="0dp"
android:left="-2dp"
android:right="-2dp"
android:top="0dp">
<shape android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#color/red" />
<solid android:color="#color/transparent" />
<padding android:left="10dp"
android:right="10dp"
android:top="5dp"
android:bottom="5dp" />
</shape>
</item>
</layer-list>
button_shape_three.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/transparent"/>
<stroke android:width="1dp"
android:color="#color/red"
/>
<corners android:bottomRightRadius="5dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="5dp"/>
</shape>
Result :
Thank you all!
You need to create a Shape drawable for all of your buttons. For eg the center button can use below drawable as background.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#606060"/>
<stroke android:color="#303030" android:width="2dp" />
</shape>
For the other two you need rounded edges only on left and right.For that you may follow This post on SO.
*Note: change the colors according to your needs and you will also require a selector to be applied on each button to highlight the selection.
The left and right borders can also be removed using shape drawable.For more details please see This post
The more easier approach will be to use This Library.
Set width to "0dp" and weight to "1" for all your buttons and wrap them inside a horizontal LinearLayout
roundedbuttons.xml in drawable
?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff"/>
<stroke android:width="3dp"
android:color="#ff000000"
/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
Edit the shape according to your preference
In your xml layout
LinearLayout(Horizontal)
- Buttons with background(roundedbuttons.xml) and weight="1"
Why don't you use one linear layout with blue border as parent of 3 textViews with background. No need to make it complicated.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I was trying to create a button similar in look to the round buttons over here -
http://livetools.uiparade.com/index.html
(every button looks like it is inside an immersed section) I had it by placing the button in a circle background and giving them both a little gradient that didnt end up the same though I got this result -
(I will upload my code once I can) how can I achieve that same look?
Try this code. I am able to produce an image that looks like this
which is similar to the first button you link to, using the following code. The key is to use <layer-list> to layer shapes one over the other to produce the desired effect.
File: res/drawable/button.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Outside border/shadow -->
<item>
<shape android:shape="oval">
<size android:width="200dp" android:height="200dp" />
<gradient android:angle="90" android:startColor="#f4f4f4" android:endColor="#b9b9b9" />
</shape>
</item>
<!-- Inset -->
<item android:top="1dp" android:left="1dp" android:right="1dp" android:bottom="1dp">
<shape android:shape="oval">
<gradient android:angle="90" android:startColor="#dcdcdc" android:endColor="#c9c9c9" />
</shape>
</item>
<!-- Inside border/shadow -->
<item android:top="15dp" android:left="15dp" android:right="15dp" android:bottom="15dp">
<shape android:shape="oval">
<gradient android:angle="90" android:startColor="#8c8c8c" android:endColor="#cbcbcb" />
</shape>
</item>
<!-- Main button -->
<item android:top="16dp" android:left="16dp" android:right="16dp" android:bottom="16dp">
<shape android:shape="oval">
<solid android:color="#ffffff" />
</shape>
</item>
<!-- Button image -->
<item android:top="70dp" android:left="70dp" android:right="70dp" android:bottom="70dp">
<shape android:shape="rectangle">
<solid android:color="#3b88c2" />
<corners android:radius="20dp" />
</shape>
</item>
<item android:top="75dp" android:left="75dp" android:right="75dp" android:bottom="75dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<corners android:radius="20dp" />
</shape>
</item>
<item android:top="80dp" android:left="80dp" android:right="80dp" android:bottom="80dp">
<shape android:shape="rectangle">
<solid android:color="#3b88c2" />
<corners android:radius="20dp" />
</shape>
</item>
</layer-list>
In your main layout, add an ImageView that will display this image.
<ImageView
android:src="#drawable/button" />
You can make the ImageView clickable by giving it an OnClickListener in the Java code.
Go to this link and Generate Custom 3D button.
http://angrytools.com/android/button/
buttonshape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="30dp"
/>
<gradient
android:gradientRadius="45"
android:centerX="35%"
android:centerY="50%"
android:startColor="##4CAB0B"
android:endColor="#004507"
android:type="radial"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#0B8717"
/>
</shape>
Button Code
<Button
android:id="#+id/angry_btn"
android:text="Button"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="270dp"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="3"
android:shadowDy="2"
android:shadowRadius="8"
/>