CSDN original question from Q channel, more solutions, see: http: //ask.csdn.net/questions/903
original problem description:
xml The textView:
& lt; TextView
android: id = "@ + id / bookTitle"
android: layout_width = "match_parent"
android: layout_height = "wrap_content"
android: layout_weight = "1"
android: drawableLeft = "@ drawable / checkmark"
android: gravity = "center_vertical"
android: textStyle = "bold"
android: textSize = "24dip"
android: maxLines = "1"
android: ellipsize = "end" / & gt;
As seen in the program I set DrawableLeft in xml.
I want to change the drawable in the code.
Is there any way you can use the code textview set drawableLeft it?
Solution:
public void setCompoundDrawables (Drawable left, Drawable top, Drawable right, Drawable bottom);
Similar call as follows:
1.
in XML
android: drawableLeft = "@ drawable / icon"
2. Code the dynamic changes
Drawable drawable = getResources () getDrawable (R.drawable.drawable);
./// This step must be done, otherwise it will not be displayed.
drawable.setBounds (0, 0, drawable.getMinimumWidth (), drawable.getMinimumHeight ());
myTextview.setCompoundDrawables (drawable, null, null, null);
Also another function or reference
public void setCompoundDrawablesWithIntrinsicBounds (Drawable left,
Drawable top, Drawable right, Drawable bottom)
Reply:
Learn. . . . .
Reply:
Landlord was amazing

Reply:

Reply:
Really very hard! We are looking for!
Reply:
Reply:

Reply:

Reply:

Reply:
Reply:

Reply:
A landlord was amazing
Reply:
Learn. . . . .
Reply:
Reply:

Reply:
Reply:
Say it a look
Reply:
Look to say it!
Reply:
TextView tv = new TextView (this);
tv.setCompoundDrawables (left, top, right, bottom);
If you just set the picture in TextView left, then the other is set to null
Reply:
Learning the

Reply:
Reply:
Terrible terrible! Learn
Reply:
Thank you, do not do it for a long time
Reply:
Reply:
You can achieve the perfect
Reply:
There is a big help, thank you
Reply:
Worship, thanks. . . Why not show the reason has not found
No comments:
Post a Comment