1

hello what i want to do is setting a value in a drawable file bg.xml here is the file

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:startColor="#ffc2e59c"
                android:centerColor="#ff3a7a7a"
                android:endColor="#ff3a7a7a"
                android:angle="135"/>
        </shape>
    </item>
</selector>

i want to change android:startColor="#ffc2e59c" if a file exists . ( i already know using if to make it use the line . ) so what i want to do is

    my lines {  

    if (filee.exists()) {

    change the color to something else 
    (android:startColor="#ffffffff")
    }

}
Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
Mr.Nikan
  • 67
  • 9

2 Answers2

0

I think the proper way of getting this done is like this:

File f = new File("cbc.db");
if(f.exists() && !f.isDirectory()) { 
    int h = v.getHeight();
    ShapeDrawable mDrawable = new ShapeDrawable(new RectShape());
    mDrawable.getPaint().setShader(new LinearGradient(0, 0, 0, h, Color.parseColor("#330000FF"), Color.parseColor("#110000FF"), Shader.TileMode.REPEAT));
    v.setBackgroundDrawable(mDrawable);
}

see this post for more information.

Community
  • 1
  • 1
jobbert
  • 3,297
  • 27
  • 43
  • I don't exactly know what you mean with "the file" do you mean the resource file exists? because this solution doesn't use a resource file. – jobbert Mar 18 '16 at 09:43
  • no . a file name cdc.db located in a folder . i already can check the file but only i need to config the "if l" line :)) – Mr.Nikan Mar 18 '16 at 09:44
0

you could just create another drawable and pragmatically add that as the background as shown here

Community
  • 1
  • 1
Shreyans
  • 1,043
  • 2
  • 14
  • 25