Hi i used linearlayout and its property android:background to make border color of it grey.
When i switch to android 4.1., from 6.0 layout background turns black (whole background not just 3dip like set).
border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="3dip"
android:color="#d3d3d3" />
</shape>
Any suggestions how to fix this?
You are missing the background color for your shape.
On newer Android versions this is transparent, but on older ones it is black.
Just add a transparent solid to your XML to fix this.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#android:color/transparent" />
<stroke
android:width="3dip"
android:color="#d3d3d3" />
</shape>
Just add property **<solid android:color="YOUR COLOR" />**
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="3dip"
android:color="#d3d3d3" />
<solid android:color="#F9671E" /> // for background color.You can change
</shape>
Related
I have a Button and I am setting as background a gradient drawable.
The buttons with the gradient drawable are missing the elevation whereas all other buttons have the elevation.
Why is the elevation missing on the buttons with the gradient drawable? And is there any easy way to fix this?
My code looks like this:
gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:type="radial"
android:gradientRadius="250dp"
android:startColor="#color/blue"
android:endColor="#color/red"/>
<corners android:radius="#dimen/round_corner_radius"/>
<stroke
android:width="5dp"
android:color="#android:color/transparent"/>
</shape>
</item>
<item android:top="7dp"
android:left="7dp"
android:right="7dp"
android:bottom="7dp">
<shape android:shape="rectangle" >
<solid android:color="#88ffffff"/>
<corners android:radius="#dimen/round_corner_radius"/>
</shape>
</item>
</layer-list>
activity.xml
...
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/button"
android:background="#drawable/gradient"/>
...
I solved my problem. I had to remove the
<stroke
android:width="5dp"
android:color="#android:color/transparent"/>
The problem was probably the color that was set. Without the stroke the button behaves like a normal raised button.
I need to create a round corner border, where border with gradient.enter link description here is working.But My page is using a image as background which is also with gradient. I need to show background image from middle of the filed. I want to create just like below image:
round_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="4dp"
android:color="#color/transparent" />
<gradient
android:startColor="#374533"
android:centerColor="#432727"
android:endColor="#222430"
android:angle="135"/>
<corners android:radius="10dp" />
</shape>
round_border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#efe301"
android:centerColor="#7dc17b"
android:endColor="#01dae6"
android:angle="180"/>
<corners android:radius="10dp" />
result_drawable.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/round_border"/>
<item android:drawable="#drawable/round_background" />
</layer-list>
Here, you can set android:width="4dp" in round_background.xml to set size of your border. use result result_drawable.xml where you want..
Enjoy. :}
I'm testing Android L Preview on my Nexus 5. I've got problem with my app.
I've got some TextViews with background set:
android:background="#drawable/rounded_textview"
And "rounded_textview" is just shape. It is working great below <=API19.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="3dp">
<solid android:color="#999999"/>
<corners
android:bottomRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"/>
</shape>
On Android L Developer Preview background is ignored. All my TextViews are transparent.
Any idea what am I doing wrong?
I found that wrapping the shape in a selector and item tag made it work
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/gray" />
<corners
android:bottomLeftRadius="3dp"
android:topRightRadius="3dp"
android:topLeftRadius="3dp"
android:bottomRightRadius="3dp" />
</shape>
</item>
</selector>
Just use android:radius, not use each corner options.
I had a same problem, but I was able to solve the problem using this way.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="3dp">
<solid android:color="#999999"/>
<corners android:radius="2dp"/>
</shape>
I'm trying to build a custom android view and apply a background drawable that is a layer-list.
The layer-list has two items:
A background color (white)
A simple shape drawable that is a stroked rectangle with rounded-corners
here's the drawable xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#android:color/white"/>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1dp" />
<stroke
android:width="2dp"
android:color="#color/background_green" />
</shape>
</item>
</layer-list>
The custom view is a class derving from Android.view.View that currently has NO functionality except the required measuring overloads.
I'm applying the background in the view definition in an activity layout:
<view
android:layout_width="match_parent"
android:layout_height="300dp"
class="com.example.widget.TestView"
android:id="#+id/view2"
android:layout_gravity="center_horizontal"
android:background="#drawable/rect_sig_cap"
android:layout_margin="20dp" />
What I expect to see is a view with a white background and a green border. What I actually see when I deploy the project is a view with a black background and a green border.
Interestingly it appears correctly in the designer preview in Android Studio. It's only when I deploy it to a device that it renders black.
Am I missing something obvious here?
For those interested, I found the solution.
I had defined the shape drawable as including only a stroke definition. Without any other inputs, this causes the fill color to be inferred as black.
In the end, a Layer-List drawable is not required at all. Instead, add a solid fill definition to the shape layer with color Transparent and it works just fine.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="#dimen/corner_radius" />
<stroke android:width="1dp"
android:color="#color/background_green" />
<solid android:color="#android:color/transparent" />
</shape>
Try this one.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#color/white" />
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="1dp" />
<stroke
android:width="2dp"
android:color="#color/background_green" />
</shape>
</item>
</layer-list>
I'd like to have a background color of a RelativeLayout similar to that of an image shown in the link below. Ignore the black strip in the bottom half of the image.
I don't want to use the image as a background of the layout. Can you give me an idea of how to proceed?
You can use gradient. Set different gradient in selector as you want. Done!
GradientDrawable.class
This is what you want, set your colors. Enjoy!
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:bottom="30dp">
<shape android:shape="rectangle" >
<corners
android:topRightRadius="8dip"
android:topLeftRadius="8dip" />
<gradient
android:startColor="#030303"
android:endColor="#3B3B3B"
android:angle="270" />
</shape>
</item>
<item android:top="30dp" >
<shape android:shape="rectangle" >
<corners
android:bottomLeftRadius="8dip"
android:bottomRightRadius="8dip" />
<gradient
android:startColor="#4B5057"
android:endColor="#4B5059"
android:angle="270" />
<size android:height="30dp" />
</shape>
</item>
</layer-list>
just try with shape file structure. I think this may give the solution.
//save this below code as gradient and use as background of your layout as
android:background="#drawable/gradient"
//gradient.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#232323" android:endColor="#4B5059"
android:angle="270"/>
</shape>