Issue
layout_bg.xml
<?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" android:color="#B1BCBE" />-->
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
main_activity.xml
<ImageButton
android:background="@drawable/layout_bg"
android:src="@drawable/myicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tint="@android:color/black"
android:minWidth="80.0dp"
android:minHeight="80.0dp"
android:padding="10px"
android:scaleType="fitCenter"
android:layout_alignParentBottom="true"
android:id="@+id/btnFoo"
android:layout_marginLeft="91.0dp"
/>
I am setting the background of my ImageButton
to a layout so I can have dynamic rounded corners as you can see in this image:
However, I need to change the background color of just that button to another solid color such as red.
If I set the background color with btnFoo.SetBackgroundColor(Color.Red)
, then the rounded corners are gone.
I assume because it overwrote the background attribute to be a solid color value rather than the layout_bg.xml
file.
How can I set the background color of this specific ImageButton
and not all the ImageButtons in my main_activity that use layout_bg
as the background?
Solution
You need to make another drawable with the color Red then use it :
btnFoo.setBackgroundResource(R.drawable.red_drawable);
Answered By - Wowo Ot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.