in the Wheat Academy forum, I saw a lot of Android beginners are asking TextView to set the Drawableleft property, I copied the question in the Wheat College Forum, and then we came together to answer:
Original problem Description:
the TextView in XML:
1.<font face= "song Body" size= "3" > <textview
2.android:id= "@+id/booktitle"
3.android:layout_width= "Match_parent"
4.android:layout_height= "Wrap_content"
5.android:layout_weight= "1"
6.android:drawableleft= "@drawableeckmark"
7.android:gravity= "Center_vertical"
8.android:textstyle= "Bold"
9.android:textsize= "24dip"
10.android:maxlines= "1"
11.</font> <font face= "song Body" size= "3" >
12.android:ellipsize= "End"/> </font>
as seen in the program, I set the Drawableleft in XML.
I want to change the drawable in the code.
is there any way you can use code to set drawableleft for TextView?
Solution:
1.<font face= "song Body" size= "3" >
2.public void Setcompounddrawables (drawable left, drawable top, drawable right, drawable bottom); </font>
similar invocation methods are as follows:
1. Using in XML
1.<font face= "song Body" size= "3" >
2.android:drawableleft= "@drawable/icon" </font>
2. Dynamic changes in the code
1.<font face= "song Body" size= "3" >
2.Drawable drawable= getresources (). getdrawable (r.drawable.drawable);
3.///This step must be done, otherwise it will not be displayed.
4.drawable.setbounds (0, 0, drawable.getminimumwidth (), Drawable.getminimumheight ());
5.mytextview.setcompounddrawables (drawable,null,null,null); </font>
also or refer to another function
1.<font face= "song Body" size= "3" >
2.public void Setcompounddrawableswithintrinsicbounds (drawable left,
3.Drawable Top, drawable right, drawable bottom)
4.</font>
in the Android interface development process, sometimes need a multi-line input, the implementation code is as follows:
1.<font face= "song Body" size= "3" > <edittext
2.android:id= "@+id/editcontent"
3.android:layout_width= "Fill_parent"
4.android:layout_height= "Wrap_content"
5.android:minlines= "3"
6.android:textsize= "18SP" </font>
More Android Development Tutorials at:
Http://www.maiziedu.com/course/android/
How to set the Drawableleft property with TextView