c# - Xamarin android 更改图标颜色

标签 c# android xamarin xamarin.android

我在编辑文本字段中有一个可绘制图标。我想更改图标的颜色。我目前使用的是 drawable tint,在 Xamarin studio designer 中工作正常,但它没有显示测试设备上的变化。

我已经尝试了从 jellybean 到 nougat 的所有设备仍然没有运气,我可能做错了什么?

最佳答案

EditText 不包含 tint 属性,但 imageview 有。如果你想改变 EditText 图标的颜色,你可以先改变 drawable 的色调,然后使用 drawable 设置 EditText 的背景:

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

这是我的布局文件:

<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>

您可以看到第二个 EditText 和 imageview 图标色调已更改:

enter image description here

关于c# - Xamarin android 更改图标颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42668308/

相关文章:

c# - 多个 REST API 方法可以共享同一个 Controller 类吗?

c# - 如何将模型集合从asp.net mvc注入(inject)backbone.js?

Android Bluemix 不显示扬声器标签

ios - 使用 ViewCellRenderer 在 iOS 上的 Xamarin Forms 中自动设置 ViewCell 高度

ios - Xcode 5.0 的 Xamarin 4.0.10 不会在设备上运行,但会在模拟器中运行

c# - 如何有效地将巨大的字符串添加到文本框?

android - 如何在模拟器中查看推送到 SD 卡的图像

java - 如何使用 Robolectric 在 Android 中测试菜单

ios - Xamarin iOS文件属性Build Action:LinkDescription不可用

c# - 是否有一种有效的手写文本分割算法?