如何使用ColorFilter

时间:2017-05-18 08:54:12

标签: java android xml android-studio

将ColorFilter用于ImageView

代码:

  ImageView im = (ImageView)findViewById(R.id.imz);
        im.setColorFilter(Color.BLACK,PorterDuff.Mode.SRC_ATOP);
        im.setBackgroundResource(R.drawable.play_button);

使用Mode.SRC.IN,Mode.MULTIPLY

但Imageview无效!

2 个答案:

答案 0 :(得分:0)

请尝试此

 ImageView im = (ImageView)findViewById(R.id.imz);
 im.setColorFilter(Color.BLACK,PorterDuff.Mode.SRC_ATOP);

答案 1 :(得分:0)

请尝试这个,

<xp:inputTextarea id="inputTextarea1" rows="5" />

ShapeDrawable的完整性,图像大小我有固定的大小。

circle_white.xml

 ImageView im = (ImageView)findViewById(R.id.imz);   
 im.getDrawable().setColorFilter(Color.BLACK, PorterDuff.Mode.MULTIPLY );

请在布局imageView中进行,

 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <solid android:color="@android:color/white" />
</shape>

也尝试这个, Check Here