[Android custom control] TextView details and custom

Source: Internet
Author: User

As one of the most common controls of android, it has the following common attributes:

Layout_width, layout_height: required properties for each control

Text: text display, INPUT attribute

TextColor: text color attribute

TextSize: Text Size

There are also some features used in some occasions

AutoLink: sets whether the text is displayed as a URL link, email, phone number, or map. The text is displayed as a clickable link.

AutoText: the spelling of the input value is automatically corrected.

DrawableBottom: Output A drawable under text.

DrawableRight: Output A drawable on the Right of text.

DrawableTop: Output A drawable on the top of the text.

Editable: Set whether to edit

Ellipsize: Set how to display the control when the text is too long

EMS: Set the width to N characters

ShadowRadius: Set the shadow radius.

ShadowColor: Specifies the color of text shadow, which must be used with shadowRadius and must be set with shadowRadius.

 

ShadowDx: Set the start position of the Shadow horizontal coordinate.

ShadowDy: Specifies the start position of the Shadow vertical coordinate.

 

There are many other attributes. These android textviews provide a lot of information. You are familiar with them and have a good grasp of some common attributes. You can check the APIs for other features.

Next, I will focus on it. When we need the TextView function of some features, but the provided api cannot meet the requirements, for example, to make a skewed Textview,

This requires customization.

Steps:

1. Write a MyTextView class to inherit the View and override the onDraw () method of the View.

2. We also need a Paint brush to help us draw TextView;

 

Paint p = new Paint (); p. setColor (Color. BLUE); p. setAntiAlias (true); // remove missing sertices

3. the paint brush is ready and the content is painted. At this time, TextView is displayed normally. to tilt TextView, We can tilt the canvas.

 

 

Canvas c = new Canvas (); c. save (); // save, which appears in pairs with restore. save the canvas status and do not affect c. rotate (45); // set the canvas to rotate 45 degrees c. drawPaint (p); c. restore ();

4. After the custom TextView is completed, we can reference it in Xml.

 

 

You're done. Do you want to go back and try it yourself?

 

 

Related Article

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.