Issue
I am trying to change background color of a button programmatically but when i change its color button disappears from screen.
Here is button in layout
<Button
android:id="@+id/ibtn_EA_ColorPick_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/clr_btn"
/>
and here is how i am changing its background
btn_ColorPick.setBackgroundColor(btn_ColorPick.getContext().getResources().getColor(R.color.BlackColor));
I have also tried
btn_ColorPick.setBackgroundColor(getResources().getColor(R.color.BlackColor));
but same result
Solution
Try using ImageButton -
<ImageButton
android:id="@+id/ibtn_EA_ColorPick_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/clr_btn"
android:background="@drawable/red_color"
/>
btn_ColorPick.setBackgroundColor(->ur color <-);
Answered By - vijay
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.