【问题标题】:How to change the color of intern Android drawables?如何更改实习生 Android 可绘制对象的颜色?
【发布时间】:2013-03-27 22:40:20
【问题描述】:

我尝试将 Android (anrdoid.R.drawable.bla) 的实习生图标放入 ImageButton 我想改变图标的​​颜色(不是背景!),但它不像我想要的那样工作。

这是我尝试过的:

布局中的我的 ImageButton:

<ImageButton
    android:id="@+id/imageButton1"
    android:layout_marginTop="100dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/background"
    android:src="@android:drawable/ic_lock_silent_mode" />

我在 Activity 中尝试过的内容:

Drawable myIcon = getResources().getDrawable( android.R.drawable.ic_lock_silent_mode); 
    ColorFilter filter = new LightingColorFilter( R.color.blue, R.color.blue);
    myIcon.setColorFilter(filter);

无论我为 LightingColorFilter 尝试了什么值,它总是给出相同的结果。 Imagebutton 内的图标变暗。但这不是我想要的。我只是想从我的colors.xml 中应用一种颜色,但不知何故不起作用。

这甚至是我要去的正确方向吗?或者是否还有其他机会(我并不是说在 Photoshop 中为自己着色并将它们放入 drawables 文件夹)

【问题讨论】:

    标签: java android colors icons drawable


    【解决方案1】:

    这对我有用,例如它会涂成深灰色:

    ImageButton imgBtn = (ImageButton) findViewById(R.id.imageButton11); // image button
                imgBtn.setColorFilter(getResources().getColor(android.R.color.darker_gray), Mode.SRC_ATOP);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多