You can add Vector Drawable to EditText programmatically. Use VectorDrawableCompat to add drawableLeft / drawableRight / drawableTop / drawableBottom / drawableStart / drawableEnd.
Steps:
I. Remove android:drawableLeft="@drawable/layer_list_ic_user"
II. If EditText is inside an Activity:
EditText etUserName= (EditText)findViewById(R.id.et_username_or_email); VectorDrawableCompat drawableCompat=VectorDrawableCompat.create(getResources(), R.drawable.layer_list_ic_user, etUserName.getContext().getTheme()); etUserName.setCompoundDrawablesRelativeWithIntrinsicBounds(drawableCompat, null, null, null);
III. If the EditText is inside the fragment:
EditText etUserName= (EditText)view.findViewById(R.id.et_username_or_email); VectorDrawableCompat drawableCompat=VectorDrawableCompat.create(getActivity().getResources(), R.drawable.layer_list_ic_user, etUserName.getContext().getTheme()); etUserName.setCompoundDrawablesRelativeWithIntrinsicBounds(drawableCompat, null, null, null);
For more information about VectorDrawableCompat see link
Arshak
source share