0

My problem is the following:

I have a Mainactivity class where I have a method, that gets a TextView with the id colorselected.

Mainactivity method:

  @Override
public void onColorSelected(int dialogId, @ColorInt int color) {
    this.color = color;
     findViewById(R.id.colorselected).setBackgroundColor(color);
    //om te tonen welke kleur geselecteerd is
}

TextView in my first XML-file:

<TextView
    android:id="@+id/colorselected"
    android:layout_width="15dp"
    android:layout_height="15dp"
    android:background="@drawable/colorselecteddrawable"
    ... />

As you can see my TextView uses a drawable called colorselecteddrawable, the code in that drawable is:

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="50dp"/>
    <solid android:color="#000000" />

</shape>

I'm trying to set the background color of the TextView, whenever the onColorSelected-method gets executed. However, if I use the method as it is now, my TextView isn't round anymore, probably because the TextView-backgroundcolor gets overwritten, without using the drawable anymore.

So my question is: how can i change my Mainactivity method, so that I can change the <solid android:color="..."/> tag into the new color, whenever the method gets executed?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1

You should add android:shape="rectangle" or android:shape="oval" in the xml code .

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle">

    <corners android:radius="50dp"/>
    <solid android:color="#000000"/>

</shape>
KeLiuyue
  • 8,149
  • 4
  • 25
  • 42
  • This didn't fix it :/ The first time it does change, but once i execute the colorselected method it just overwrites the drawable – Pieter Desseyn Nov 11 '17 at 12:19
  • You should add a shape for selected status .Then you can use it in your xml code . – KeLiuyue Nov 11 '17 at 12:23
  • And then you can add `select.xml` for `shape` normal and `shape` selected . – KeLiuyue Nov 11 '17 at 12:24
  • And you can check this link [https://stackoverflow.com/questions/1219312/android-selector-text-color](https://stackoverflow.com/questions/1219312/android-selector-text-color)@PieterDesseyn – KeLiuyue Nov 11 '17 at 12:26