0

I have setup a circle (shape) in an xml for a drawable right on a toggle button. The circle.xml has an initial color of green but I cannot get it to show on button. When I used image I am able to see the image so I am sure the issue is with the circle or shape. This it he toggle button with the drawable right.

<ToggleButton
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_weight="1"
    android:background="@drawable/custom_fixture_buttons"
    android:textColor="@drawable/white"
    android:textOff="F1"
    android:textOn="F1"
    android:drawableRight="@drawable/circle"
    android:textSize="30sp" />

This is the code for the circle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/circle"
    android:shape="oval"
    android:color="#ff00FFFF" >
</shape>

I have a total of 10 toggle buttons with the drawable right and need to change the colors of each of them separatly, here is a method to set each of the color dots. The first generation used a separate image over each button but I need to change code to apply this to the toggle button drawableright. I tried the setCompoundDrawablesWithIntrinsicBounds but get errors.

switch (index) {
    case 0: {
        Resources res = getResources();
        final Drawable drawable = res.getDrawable(R.drawable.circle);
        drawable.setColorFilter(Color.rgb(i, j, k), Mode.SRC_ATOP);
        // ImageView img = (ImageView) findViewById(R.id.colordot1);
        // img.setBackgroundDrawable(drawable);
        // Fixture1.setCompoundDrawablesWithIntrinsicBounds(0, 0,img, 0);
        break;
}
codeling
  • 11,056
  • 4
  • 42
  • 71
Bobby
  • 659
  • 2
  • 13
  • 26

1 Answers1

0

You've created the drawable incorrectly.

Here's an example of a drawable that would create a coloured circle:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >

    <solid 
        android:color="#00FFFF" />

</shape>
Evan Bashir
  • 5,501
  • 2
  • 25
  • 29
  • I made the changes but the circle still does not appear in the toggle button – Bobby Jan 09 '14 at 19:03
  • Perhaps there's a better way of doing what you want. Can you please explain what you're trying to accomplish? Pictures & Layout code help. – Evan Bashir Jan 09 '14 at 19:46
  • I am trying to add a color circle do the button with drawableright. I need to control the circle fill color with an RGB color. I posted the code above for the toggle button and the code used to change the color. The circle is not showing up – Bobby Jan 09 '14 at 19:55
  • Don't bother with drawableRight. Just nest your ToggleButton in a LinearLayout set to Horizontal Orientation, with an ImageView that has your circle in it. – Evan Bashir Jan 09 '14 at 19:58
  • I already tried that. I need the circle inside the button. here is a post I talked about the needs.http://stackoverflow.com/questions/20926283/image-view-over-button-in-tablelayout – Bobby Jan 09 '14 at 20:06
  • I have successfully done this with a Relative layout but my design required a Linear layout which posses the problem to set the position. – Bobby Jan 09 '14 at 20:09