setCompoundDrawablesRelativeWithIntrinsicBounds - How to Add a Drawable to the Start of Text, in a TextView, in Java
setCompoundDrawablesRelativeWithIntrinsicBounds was added in API Level 17
Related XML Attribute: android:drawableStart
setCompoundDrawablesRelativeWithIntrinsicBounds (int start, int top, int end, int bottom)Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.
Related XML Attribute: android:drawableStart
setCompoundDrawablesRelativeWithIntrinsicBounds (int start, int top, int end, int bottom)Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.
1. Ensure to change the minSDKVersion to 17, or greater.
4. Add the code below to the onCreate method. This will set a drawable to be drawn to the end of the text.
- myTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.myImage,0,0,0);
Related Articles: