有没有办法强制android.support.v7.appcompat.R.drawable.abc_ic_clear_mtrl_alpha为白色

时间:2016-04-18 14:34:37

标签: android colors

目前,我的应用正在使用Theme.AppCompat.Light.NoActionBar

我有一个自定义搜索视图,当有文字时会显示关闭按钮。

public class JStockSearchView extends LinearLayoutCompat {

    public JStockSearchView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        final LayoutInflater inflater = (LayoutInflater) context.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.jstock_search_view, this, true);

        mSearchSrcTextView = (JStockAutoCompleteTextView) findViewById(R.id.search_src_text);
        mCloseButton = (ImageView) findViewById(R.id.search_close_btn);
        mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);

        mCloseButton.setImageDrawable(getResources().getDrawable(android.support.v7.appcompat.R.drawable.abc_ic_clear_mtrl_alpha));

但是,十字标记显示为黑色。

enter image description here

有没有办法强制它变成白色?

2 个答案:

答案 0 :(得分:1)

AppCompat资源可能会在将来的更新中更改。您应该在资源中放置一个关闭按钮,然后使用该抽屉。

如果您想使当前可绘制的白色,则可以应用ColorFilter。例如:

mCloseButton.setColorFilter(Color.WHITE);

您还可以将ColorFilter应用于Drawable

Drawable closeDrawable = getResources().getDrawable(android.support.v7.appcompat.R.drawable.abc_ic_clear_mtrl_alpha);
closeDrawable = closeDrawable.mutate(); // don't apply the ColorFilter everywhere
closeDrawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
mCloseButton.setImageDrawable(closeDrawable);

要使用您自己的图片,您可以在Android Studio中使用矢量绘图导入,或从materialdesignicons.com获取图片。

答案 1 :(得分:0)

尝试在colors.xml中创建一个新的颜色变量,并将其指定给十字标记,而不是强制。

https://design.google.com/icons/下载另一个十字图标(您可以在此处选择白/黑)

相关问题