可以提供Android SDK图标设置颜色?

时间:2016-10-16 22:57:16

标签: android android-icons

Android SDK提供以下图标。

有没有办法为那些设置颜色..如果可能的话,怎么办?

    <ImageView
        android:id="@+id/share_button"
        style="@style/IconNav"
        android:src="@android:drawable/ic_menu_share"/>

    <ImageView
        android:id="@+id/bookmark_button"
        style="@style/IconNav"
        android:src="@android:drawable/ic_input_get"/>

enter image description here

更新

在完成项目的完全刷新之后,事实证明Xml中的tint属性可以完成。

  

简短回答

     

..这是适合我的解决方案 - 将属性添加到ImageView xml:

    android:tint="@color/grass_dark"

@goldenb的答案是彻底解决了解决这个问题的不同方法,所以我将这一点作为答案。

2 个答案:

答案 0 :(得分:3)

您确实可以使用色调作为更改ImageView颜色的方式,但是应提醒您始终应用android:tint在原始颜色之上。

博客danlew

所述

  
      
  • ImageView的色调将色调颜色与原始资源混合。你想要的是色调颜色完全接管;相反   将色调应用于现有颜色的顶部。所以,例如,如果   源资产是黑色的,你希望它是#77FFFFFF(半透明的   白色的阴影),你实际上最终得到了白色的阴影   在它下面有黑色背景。

  •   
  • android:tint仅限于ImageView。您希望能够在任何视图中为任何Drawable着色。

  •   

一种可能的替代方法是使用android ColorFilter

根据official documentation

  

滤镜可以与“Paint”一起使用,以修改使用该绘制绘制的每个像素的颜色。这是一个永远不应该直接使用的抽象类。

使用ColorFilter可以做很多或多或少复杂的事情,但是你怎么能应用呢?

另一个简单的example问题是:

//White tint
imageView.setColorFilter(Color.argb(255, 255, 255, 255)); 

or

imageView.setColorFilter(ContextCompat.getColor(context,R.color.COLOR_YOUR_COLOR))

或者来自here

的SO中更完整的答案
ImageView redCircle = (ImageView) findViewById(R.id.circle_red_imageview);
ImageView greenCircle = (ImageView) findViewById(R.id.circle_green_imageview);
ImageView blueCircle = (ImageView) findViewById(R.id.circle_blue_imageview);



// we can create the color values in different ways:
redCircle.getDrawable().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY );
greenCircle.getDrawable().setColorFilter(0xff00ff00, PorterDuff.Mode.MULTIPLY );
blueCircle.getDrawable().setColorFilter(getResources().getColor(R.color.blue), PorterDuff.Mode.MULTIPLY );

如果您想了解更多信息,请查看这些链接

SO - What is the difference between background, backgroundTint, backgroundTintMode attributes in android layout xml?

setColorFilter()

Fast Android asset theming with ColorFilter

SO-Modifying the color of an android drawable

答案 1 :(得分:1)

您可以使用带色调的位图。将其添加到drawables文件夹中。

ic_input_get_colored.xml:

"drag_text": false