【问题标题】:Xamarin android changing icon colourXamarin android更改图标颜色
【发布时间】:2017-07-28 20:12:59
【问题描述】:

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

我已经尝试了从果冻豆到牛轧糖的所有设备仍然没有运气,我可能做错了什么?

【问题讨论】:

    标签: c# android xamarin xamarin.android


    【解决方案1】:

    EditText 不包含 tint 属性,但 imageview 有。如果你想改变EditText图标的颜色,你可以先改变drawable tint,然后用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 图标色调已经改变:

    【讨论】:

    • 非常感谢! +100 直接简单的答案,希望不再是 xam 菜鸟。
    猜你喜欢
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    相关资源
    最近更新 更多