setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) not working

Viewed 10972

I have a few EditText views where I want to set the image on the left and setCompoundDrawablesWithIntrinsicBounds does not seems to be working. The graphics do not seem to be getting changed.

does anyone know why this might be the case?

Here is how I am setting the drawables:

        mFirstname.setCompoundDrawablesWithIntrinsicBounds(R.drawable.user_icon, 0, 0, 0);
        mLastname.setCompoundDrawablesWithIntrinsicBounds(R.drawable.user_icon, 0, 0, 0);
        mEmail.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
        mPassword.setCompoundDrawablesWithIntrinsicBounds(R.drawable.lockicon, 0, 0, 0);
        mDateOfBirth.setCompoundDrawablesWithIntrinsicBounds(R.drawable.calico, 0, 0, 0);
        mCity.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
        mStreet.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
        mPostcode.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
        mPhoneNumber.setCompoundDrawablesWithIntrinsicBounds(R.drawable.mailicon, 0, 0, 0);
5 Answers
mBtnNext=(Button) rootView.findViewById(R.id.btnNext);

Drawable drawableRight=new IconicsDrawable(getActivity().getApplicationContext())
               .icon(Ionicons.Icon.ion_arrow_right_a)
                .color(getResources().getColor(R.color.colorBlack))
                .sizeDp(24);

mBtnNext.setCompoundDrawables(null,null,drawableRight,null);

Try this your problem will get resolved.

I used Ionicons plugins. Go to the following links. You will get some idea about how to use IonIcons in your android project.

IonIcons For Android

After implement the above Ionicons plugins in your project. You will get IconicsDrawable class.

Gradle image

See here to know how to drive IconicsDrawable class in your class

mBtnNext=(Button) rootView.findViewById(R.id.btnNext);

Drawable drawableRight=new IconicsDrawable(getActivity().getApplicationContext())
               .icon(Ionicons.Icon.ion_arrow_right_a)
                .color(getResources().getColor(R.color.colorBlack))
                .sizeDp(24);

mBtnNext.setCompoundDrawables(null,null,drawableRight,null);

I hope you will understand now.

Related