How to set the Drawableleft property with TextView

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.