0

I'm trying to set a DropDown Background Color for a autocompleteTextView, because the standart Values seem to be different during different Android Versions. For example, everything works fine starting with android 3.2, but previous Versions seem to not accept the android:textColor="@color/black" in the xml, cause it is not working for me. Android 2.3 for example just shows the items in the list and the ones I picked in white, which isn't working for me, cause the background is white too. So I decided to change the background Color determing on the android version using this:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB){
        // Do something for Honeycomb and above versions
        //everything is right
    } else{
        // do something for phones running an SDK before froyo
        box_Kurs.setDropDownBackgroundResource(Color.BLUE);
        box_Teacher.setDropDownBackgroundResource(Color.BLUE);
    }

But when I start my app it crashes and shows resource not found exception:

11-19 15:40:17.225: E/AndroidRuntime(450): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shr.khg/com.shr.khg.AddActivity}: android.content.res.Resources$NotFoundException: Resource ID #0xff0000ff

What am I doing wrong? I alread cleaned my project since that what other people suggested. Or is there any easier way to deal with my issue?

Thank you!

2 Answers2

2

The problem is that the setDropDownBackgroundResource() is expecting the id of the Color resource Drawable, not an int that defines a Color. If you look at the Exception you can see that Android is trying to find a component with id #0xff0000ff, this is the hex code for a completely opaque blue which is the value of Color.BLUE

Emmanuel
  • 13,083
  • 4
  • 39
  • 53
0

Replce these two lines:

box_Kurs.setDropDownBackgroundResource(Color.parseColor("#0000ff"));
box_Teacher.setDropDownBackgroundResource(Color.parseColor("#0000ff"));
Naddy
  • 2,664
  • 6
  • 25
  • 38