Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set color for the rounded corners in android

Tags:

android

in my app i want to place a rounded corner background in an activity. The image i want is as follows enter image description here

The background image of my app is to be a white screen and inside my rounded corner background i need white spaces. So to identify corners of the rounded background i need to give a black color for it. But my image appears as follows. enter image description here

Following is my code for rounded background

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="#ffffff" /> 
  <stroke android:width="3dp" color="#ff000000" /> 
  <corners android:radius="15dp" android:color="#ababab" /> 
  <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> 
</shape>

How to get the black color as my corner color

like image 757
Siva K Avatar asked Nov 27 '22 09:11

Siva K


2 Answers

Here's an example that does almost exactly what you request:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#FFFFFFFF" android:endColor="#A4A4A4"
        android:angle="270" />
    <corners android:radius="5dp" />
    <stroke android:color="#4B4B4B" android:width="1dp" />
</shape>

From the great tutorial at: http://blog.stylingandroid.com/

like image 163
Josh Avatar answered Dec 16 '22 02:12

Josh


It's a bit hard to understand what you actually want to achieve, but assuming you've added

 <corners ... android:color="#ababab" /> 

You want to make you cornewr to have color #ababab.


First file named shape.xml should have the xml from your answer:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="#ffffff" /> 
  <stroke android:width="3dp" color="#ff000000" /> 
  <corners android:radius="15dp" /> 
  <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> 
</shape>

Note how I removed android:color="#ababab" from your example in <corners> tag.

Second file named solid.xml should have next xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="#ababab" />   
</shape>

Finally, the file named background.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/solid" />        
    <item android:drawable="@drawable/shape" />
</layer-list>

You should use @drawable/background for background in your activity.

enter image description here

like image 25
inazaruk Avatar answered Dec 16 '22 00:12

inazaruk