I have a shape
in layer-list
and my goal is to change color of the shape
programmatically at runtime. I have String for HEX code and I used Color.parseColor()
to parse it and I passed to setColor method. Whenever I run the application it shows different color then I expect.
Here is my code for XML file :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/lvbg"
android:top="1dp">
<shape
android:id="@+id/listview_background"
android:shape="rectangle" >
<size
android:height="220dp"
android:width="600dp" >
</size>
<solid android:color="@android:color/black"></solid>
<corners android:radius="15dp" />
</shape>
</item>
</layer-list>
And this is my code in CustomAdapter
:
convertView = mInflater.inflate(R.layout.student_info_selection_fragment_icon, null);
holder = new ViewHolder();
holder.collegeBG=(LayerDrawable)convertView.getResources().getDrawable(R.drawable.rectangle);
holder.bg = (GradientDrawable)holder.collegeBG.findDrawableByLayerId(R.id.lvbg);
String color = "#FF" + rowItem.getCollegeColor();
holder.bg.setColor(Color.parseColor(color));
For example when I put #FF1D0A63
I get black or brown, totally different colors.
Thanks