Android Development Self-study note (Android Studio) -4.2textview and its subclasses

Source: Internet
Author: User

First, Introduction

TextView is one of our most used controls, similar to the jlable in Lable,java swing programming in C # WinForm programs, but it's more powerful, but functionally, it's a text editor, and it just turns off the editing function by default. and edittext this edit box control is its immediate subclass. Let's look at the inheritance relationship for TextView in the API (API Level23):

As we can see from the API documentation, TextView directly inherits the view class and is the parent of the EditText, Button, CheckBox, and radiobutton that we commonly use.

Direct subclasses are: Appcompattextview, Button, Checktextview, chronometer, DigitalClock, EditText, Rowheaderview, Textclock

Indirect subclasses are: Appcompatautocompletetextview, Appcompatradiobutton, Autocompletetextview, CheckBox, Compoundbutton, Extractedittext, Multiautocompletetextview, RadioButton, Searchedittext, Switch, Switchcompat, ToggleButton

Let's focus on the properties of the TextView, and the other subclasses have a basic way of using them.

Second, TextView

TextView provides a number of XML attributes that apply not only to TextView, but also to his subclasses, with descriptions of these properties and their properties (based on API LEVEL23):

(I want to put the properties of the API to turn over, too many AH ah ah ah ah ah, here to borrow crazy handout ... It's enough. )

The following is a simple demonstration of how to use the code, the other self-pondering it.

Description

1.TEXT1 is a font color set using the TextColor property, the Textsize property sets the font size

2.text2 use Layout_margin to set the margin of the component, up or down is 20dp,autolink to allow the component to directly identify the hyperlink as an address

3.TEXT3 uses Layout_marginleft to set the left margin of the component, MaxLength sets the maximum length of the text in the component, and we can see that more than 7 characters later do not show

Third, the function and usage of edittext

EditText is very similar to TextView, and it uses most of the properties and methods of TextView. The biggest difference is that EditText supports user input. And the TextView property of the input is prepared for it, we look at its basic usage.

Description

1.hint is the default filled text and disappears after you get focus

2.inputType is the type that qualifies the input (enumeration type check API)

Iv. function and usage of button

Button also inherited the TextView, in the interface to display a bit a button, the user clicked the next trigger OnClick method, the simple way to use see:

Description

1. Button 1 Shadows the text

2. Button 2 Adds a background color to the button

3. Button 1 Event added using the method generated directly in the layout page bindings

4. Button 2 event is added by manual binding on code page

The function of a lot of buttons, here is only a simple introduction of the use of methods, extended use of the Internet also has a lot of introduction, here no longer one by one demo, give some learning Web site for your reference:

1.ImageButton (button with icon)

2.Android Basic Interface-button controls

The Zoombutton zoom button of the 3.Android control

4.Android button with press-down effect

5.Android Button Landscaping Example

6.Android implementation of custom button with text and pictures

V. RadioButton and checkboxes

The checkbox and RadioButton controls are only checked and unchecked, except that RadioButton is a radio button that needs to be compiled into a radiogroup, and only one button in a Radiogroup is selected at the same time.

The following are common methods and instructions for the checkbox and RadioButton.

The code is as follows:

Let's take a look at how to get the selected state:

Vi. How to use the status switch (ToggleButton) and the switching (switch)

Both switches are derived from the button, so the button's properties apply to both of them, and they are essentially buttons, similar to a checkbox, but they are typically used to switch between certain states.

Some of the properties supported by ToggleButton:

Some of the properties that switch supports:

The following code simply shows how to use it:

Vii. Conclusion

Many of the components introduced in this article are TextView subclasses, so basic use is not much difficult, but want to do better, need to study more deeply. Attached are some extended use cases.

1.android user Interface EditText Tutorial instance sinks

2.android user interface text editing tutorial instance sinks

3.android User Interface CheckBox Tutorial Example Summary

4.android User Interface TextView Tutorial Example Summary

Android Development Self-study note (Android Studio) -4.2textview and its subclasses

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.