Example usage for android.graphics.drawable Drawable setColorFilter

List of usage examples for android.graphics.drawable Drawable setColorFilter

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable setColorFilter.

Prototype

public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) 

Source Link

Document

Specify a color and Porter-Duff mode to be the color filter for this drawable.

Usage

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void applyBackground(final View view, final int color) {
    if (view == null)
        return;/*from  ww w.ja  va2s  .  com*/
    try {
        final Drawable bg = view.getBackground();
        if (bg == null)
            return;
        final Drawable mutated = bg.mutate();
        if (mutated == null)
            return;
        mutated.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        view.invalidate();
    } catch (final Exception e) {
        e.printStackTrace();
    }
}

From source file:com.example.domiter.fileexplorer.dialog.BaseDialogFragment.java

private Drawable tintDrawable(Drawable drawable, int tint) {
    Drawable d = drawable.getConstantState().newDrawable(getActivity().getResources()).mutate();
    d.setColorFilter(tint, PorterDuff.Mode.SRC_IN);
    return d;//from w w w  . j  a v  a2 s  .  co  m
}

From source file:com.flytechnology.adlicense.SignUp.java

public void editTextLineColor() {

    Drawable drawable = etUsername.getBackground(); // get current EditText drawable
    drawable.setColorFilter(ContextCompat.getColor(this, R.color.linecolor), PorterDuff.Mode.SRC_ATOP); // change the drawable color

    if (Build.VERSION.SDK_INT > 16) {
        etUsername.setBackground(drawable); // set the new drawable to EditText
    } else {/*from   www.  ja v a  2  s  . co m*/
        etUsername.setBackgroundDrawable(drawable); // use setBackgroundDrawable because setBackground required API 16
    }

    Drawable drawable1 = etPassword.getBackground(); // get current EditText drawable
    drawable.setColorFilter(ContextCompat.getColor(this, R.color.linecolor), PorterDuff.Mode.SRC_ATOP); // change the drawable color

    if (Build.VERSION.SDK_INT > 16) {
        etPassword.setBackground(drawable); // set the new drawable to EditText
    } else {
        etPassword.setBackgroundDrawable(drawable1); // use setBackgroundDrawable because setBackground required API 16
    }

    Drawable drawable3 = etEmail.getBackground(); // get current EditText drawable
    drawable.setColorFilter(ContextCompat.getColor(this, R.color.linecolor), PorterDuff.Mode.SRC_ATOP); // change the drawable color

    if (Build.VERSION.SDK_INT > 16) {
        etEmail.setBackground(drawable); // set the new drawable to EditText
    } else {
        etEmail.setBackgroundDrawable(drawable3); // use setBackgroundDrawable because setBackground required API 16
    }

    Drawable drawable4 = etAge.getBackground(); // get current EditText drawable
    drawable.setColorFilter(ContextCompat.getColor(this, R.color.linecolor), PorterDuff.Mode.SRC_ATOP); // change the drawable color

    if (Build.VERSION.SDK_INT > 16) {
        etAge.setBackground(drawable); // set the new drawable to EditText
    } else {
        etAge.setBackgroundDrawable(drawable4); // use setBackgroundDrawable because setBackground required API 16
    }
}

From source file:com.flytechnology.adlicense.MainActivity.java

public void init() {
    tvRegister = (TextView) findViewById(R.id.tv_register);
    tvConsulting = (TextView) findViewById(R.id.tv_consulting);
    etUsername = (EditText) findViewById(R.id.et_username);
    etPassword = (EditText) findViewById(R.id.et_password);

    btLogin = (Button) findViewById(R.id.bt_login);

    Drawable drawable = etUsername.getBackground(); // get current EditText drawable
    drawable.setColorFilter(ContextCompat.getColor(this, R.color.linecolor), PorterDuff.Mode.SRC_ATOP); // change the drawable color

    if (Build.VERSION.SDK_INT > 16) {
        etUsername.setBackground(drawable); // set the new drawable to EditText
    } else {/*w ww . jav a2 s  .  c  o m*/
        etUsername.setBackgroundDrawable(drawable); // use setBackgroundDrawable because setBackground required API 16
    }

    Drawable drawable1 = etPassword.getBackground(); // get current EditText drawable
    drawable.setColorFilter(ContextCompat.getColor(this, R.color.linecolor), PorterDuff.Mode.SRC_ATOP); // change the drawable color

    if (Build.VERSION.SDK_INT > 16) {
        etPassword.setBackground(drawable); // set the new drawable to EditText
    } else {
        etPassword.setBackgroundDrawable(drawable1); // use setBackgroundDrawable because setBackground required API 16
    }

}

From source file:ca.rmen.android.scrumchatter.dialog.ProgressDialogFragment.java

/**
 * @return an indeterminate, non-cancelable, ProgressDialog with a message.
 *//*from   w w  w.j a  v a 2  s  .  com*/
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState);
    ProgressDialog dialog = new ProgressDialog(getActivity());
    Bundle arguments = getArguments();
    dialog.setMessage(arguments.getString(DialogFragmentFactory.EXTRA_MESSAGE));
    dialog.setIndeterminate(true);
    dialog.setOnShowListener(shownDialog -> {
        ProgressBar progressBar = (ProgressBar) ((ProgressDialog) shownDialog)
                .findViewById(android.R.id.progress);
        if (progressBar != null) {
            Drawable drawable = progressBar.getIndeterminateDrawable();
            if (drawable != null) {
                drawable.setColorFilter(
                        ContextCompat.getColor(getActivity(), R.color.scrum_chatter_accent_color),
                        android.graphics.PorterDuff.Mode.SRC_IN);
            }
        }
    });
    dialog.setCancelable(false);
    return dialog;
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static void applyBackground(final View view, final int color) {
    if (view == null)
        return;/*from  www  .  j  a v  a  2  s  . c o m*/
    try {
        final Drawable bg = view.getBackground();
        if (bg == null)
            return;
        final Drawable mutated = bg.mutate();
        if (mutated == null)
            return;
        mutated.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        view.invalidate();
    } catch (final Exception e) {
        Crashlytics.logException(e);
        e.printStackTrace();
    }
}

From source file:com.events.events.features.welcome.SelectCityFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_select_city, container, false);
    ButterKnife.bind(this, view);

    ArrayAdapter<String> cityAdapter = new ArrayAdapter<>(getActivity(), R.layout.spinner_item);
    cityAdapter.addAll(getResources().getStringArray(R.array.cities));
    mSelectCitySpinner.setAdapter(cityAdapter);

    Drawable.ConstantState constantState = mSelectCitySpinner.getBackground().getConstantState();
    if (constantState != null) {
        Drawable spinnerDrawable = constantState.newDrawable();
        spinnerDrawable.setColorFilter(ContextCompat.getColor(getActivity(), android.R.color.white),
                PorterDuff.Mode.SRC_ATOP);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            mSelectCitySpinner.setBackground(spinnerDrawable);
        } else {//from w  ww  .  j a  v  a 2  s  .  c om
            //noinspection deprecation
            mSelectCitySpinner.setBackgroundDrawable(spinnerDrawable);
        }
    }

    mSelectCitySpinner.setTitle(getActivity().getResources().getString(R.string.select_city_spinner_title));
    mSelectCitySpinner
            .setPositiveButton(getActivity().getResources().getString(R.string.select_city_spinner_close));

    mContinueButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AnimUtils.animteViewsOut(new ViewPropertyAnimatorListener() {
                @Override
                public void onAnimationStart(View view) {

                }

                @Override
                public void onAnimationEnd(View view) {
                    ((WelcomeActivity) getActivity()).nextSlide();
                }

                @Override
                public void onAnimationCancel(View view) {

                }
            }, mContinueButton, mSelectCitySpinner, mSelectCityTitle, mSelectCityImage);
        }
    });

    AnimUtils.alphaZero(mSelectCityImage, mSelectCitySpinner, mSelectCityTitle, mContinueButton);

    return view;
}

From source file:ohgo.vptech.smarttraffic.main.LicenseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_license);
    getPrivary();//www  .  j  a  v  a 2 s.  com

    ActionBar ab = getSupportActionBar();
    Utilities.createCustomTitleActionbar(this, getResources().getString(R.string.title_license), ab);

    final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    upArrow.setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setHomeAsUpIndicator(upArrow);

    btn_accept = (Button) findViewById(R.id.btn_accept);
    tv_lisence = (TextView) findViewById(R.id.tv_lisence);
    cardview = (CardView) findViewById(R.id.cardview);

    btn_accept.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(LicenseActivity.this, SignInUpActivity.class);
            startActivity(intent);
        }
    });

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter("log_in_success"));

}

From source file:es.voghdev.prjdagger2.ui.renderer.UserRenderer.java

private void transformImageWithPorterDuff(ImageView imageView) {
    Drawable background = ContextCompat.getDrawable(mContext, R.drawable.rounded_edges);
    background.setColorFilter(ContextCompat.getColor(mContext, R.color.light_gray), PorterDuff.Mode.SRC_OVER);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        imageView.setBackground(background); // setBackground requires minSdkVersion >= 16!!
    } else {/*from ww  w.j  av  a  2 s.co  m*/
        imageView.setBackgroundDrawable(background); // setBackground requires minSdkVersion >= 16!!
    }
}

From source file:com.agenmate.lollipop.addedit.AddEditActivity.java

@SuppressLint("NewApi")
public void setBarColor(int color, boolean isWhiteText) {
    appBar.setBackgroundColor(ContextCompat.getColor(this, colorBarIds[color]));
    String title = taskId == null ? "New Task" : "Edit Task";
    toolbar.setTitleTextColor(isWhiteText ? Color.WHITE : Color.BLACK);
    toolbar.setTitle(title);//from w w  w .ja  v a  2s  . c o m
    final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_material);
    upArrow.setColorFilter(isWhiteText ? Color.WHITE : Color.BLACK, PorterDuff.Mode.SRC_ATOP);
    getSupportActionBar().setHomeAsUpIndicator(upArrow);
    setStatusBarColor(color);

    if (menu != null) {
        for (int i = 0; i < menu.size(); i++) {
            Drawable drawable = menu.getItem(i).getIcon();
            if (drawable != null) {
                drawable.mutate();
                drawable.setColorFilter(isWhiteText ? Color.WHITE : Color.BLACK, PorterDuff.Mode.SRC_ATOP);
            }
        }
    }

}