user6602747
user6602747

Reputation:

Xamarin android changing icon colour

I have a drawable icon in an edit text field. I want to change the color of the icon. What I'm currently using is drawable tint, works fine in Xamarin studio designer but it doesn't show the changes on the tested device.

I have tried all devices from jellybean to nougat still no luck, anything I might be doing wrong?

Upvotes: 1

Views: 2098

Answers (1)

Mike Ma
Mike Ma

Reputation: 2027

EditText does not contain the tint property, but imageview has. If you want to change the color of the icon of EditText you can change the drawable tint first and then use the drawable to set the EditText background:

  EditText et2 = FindViewById<EditText>(Resource.Id.edittext2);
  Drawable myicon = GetDrawable(Resource.Drawable.Icon);
  myicon.SetTint(Color.Red);
  et2.Background = myicon;

this is my layout file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <EditText
        android:id="@+id/edittext"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@drawable/icon" />
    <EditText
        android:id="@+id/edittext2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@drawable/icon" />
    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/icon"
        android:tint="#330000FF" />
</LinearLayout>

You can see the second EditText and the imageview icon tint have been changed :

enter image description here

Upvotes: 2

Related Questions