Sunday, January 10, 2016

Use code textview set drawableLeft




            


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:
The reply to be removed administrator 2013-03-07 09:07:08

Reply:

Reply:

Reply:

Reply:
The reply to be removed administrator 2013-03-08 16:36:45

Reply:

Reply:
A landlord was amazing
Reply:
Learn. . . . .
Reply:
The reply to be removed administrator 2013-03-11 11:23:18

Reply:

Reply:
The reply to be removed administrator 2013-03-12 20:06:55

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:
The reply to be removed administrator 2013-03-13 15:22:32

Reply:
Terrible terrible! Learn
Reply:
Thank you, do not do it for a long time
Reply:
The reply to be removed administrator 2013-09-18 13:49:25

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