0

I'm trying to use a background color for a listview. But i cannot find the RGB color codes that i need.

I'm using this xml code to put a background color .And it works correctly but it's not the color i want.

I'm trying to use a background like this for my listview

enter image description here

My xml code for listview background color

<?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="3dip" />
         <stroke android:width="1dip" android:color="#5e7974" />
         <gradient android:angle="-90" android:startColor="#345953" android:endColor="#689a92"  />            
     </shape>
 </item>
<item android:state_focused="true">
     <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#5e7974" />
         <solid android:color="#58857e"/>       
     </shape>
 </item>  
<item >
    <shape android:shape="rectangle"  >
         <corners android:radius="3dip" />
         <stroke android:width="1dip" android:color="#5e7974" />
         <gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />            
     </shape>
 </item>
</selector>
CraZyDroiD
  • 6,622
  • 30
  • 95
  • 182

2 Answers2

1

First thing the color which your using is gradient effect you can achieve it through coding as i am mentioning below

in your case

<gradient
android:angle="270"
android:startColor="#808080"
android:endColor="#363636"
android:type="linear"
/>

angle will be 270, type will be linear and color as i mentioned above

SAMPLE SNIPPEST HOW TO USE

code in your XML file for Button (this is sample snippest for your understanding)

<Button
android:id="@+id/button1"
android:text=""
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="270dp"
android:layout_height="60dp"
android:background="@drawable/buttonshape"
/>

and save below code in file buttonshape.xml and put that file in drawable folder under res folder

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="7dp"
/>
<gradient
android:angle="270"
android:startColor="#808080"
android:endColor="#363636"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
</shape>

for reference you can use this online tool it will help you lot please click here for online tool

hope this will help you happy coding

0

In Color code, #RRGGBB, R is the code for red, G is the code for green while B is the code for blue.

To get grey color, the RR, GG, and BB values have to be of same value e.g. #454545.

Smaller values give you darker shade of grey while larger values give you lighter shade of grey. For example #222222 is darker than #AAAAAA.

The code that is similar to the image you post is #454545. Hope that helps.

Yuan Shing Kong
  • 674
  • 5
  • 15