(Android Studio) Add a text box

Source: Internet
Author: User

Most of this article was excerpted from http://hukai.me/android-training-course-in-chinese/basics/firstapp/building-ui.html

Android:id

This is the unique identifier that defines the view. You can refer to an object by that identifier in your program code, such as an operation to read and modify the object (which will be used in the next lesson).

You must use the @ symbol when you want to reference a resource object from XML. Immediately after the @ is the type of the resource (here id ), and then the name of the resource (used here edit_message ).

The + sign is only needed when you first define a resource ID. This is to tell the SDK that this resource ID needs to be created. After the application is compiled, the SDK can use the ID value directly, edit_message is gen/R.java creating a new identifier in the project file, which is associated with the edittext. Once the resource ID is created, the other resource will no longer need the + number if it references the ID. Here is the only attribute that needs a + sign.

Android:layout_width and Android:layout_height

For width and height it is not recommended to specify a specific size, the wrap_content view will occupy only the space of the content size after using the specified. If you use it, the edittext will be filled with the match_parent entire screen, because it will fit the size of the parent layout. For more information, please refer to the Layout wizard.

Android:hint

When the text box is empty, the string is displayed by default. The resource referenced for the value of the string @string/edit_message should be defined in a separate file instead of using the string directly. Because the value used is a resource that exists, you do not need to use the + sign. However, since you have not defined the value of the string, a @string/edit_message compilation error will occur at the time of the addition. Below you can define string resource values to remove this error.

Note: The string resource uses the same name as the ID (edit_message). However, references to resources are type-sensitive (such as ID and string), so using the same name does not cause a conflict.

(Android Studio) Add a text box

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.