Attributes of edittext in Android

Source: Internet
Author: User

Edittext inheritance relationship: View --> textview --> edittext.
Edittext has many attributes. Here we will introduce several attributes:
Android: layout_gravity = "center_vertical"
Set the display position of the control: Top by default, which is displayed in the center and bottom.
Android: hint = "enter a number! "
Set the prompt information displayed on the space
Android: Numeric = "integer"
Only integers can be entered. If decimal is used, decimal is used.
Android: singleline = "true"
Set single-line Input. Once set to true, the text will not wrap automatically.
Android: Password = "true"
Set only passwords
Android: textcolor = "# ff8c00"
Font color
Android: textstyle = "bold"
Font, bold, italic, bolditalic
Android: textsize = "20dip"
Android: Capitalize = "characters"
Uppercase/lowercase letters
Android: textalign = "center"
Edittext does not have this attribute, but textview has, center
Android: textcolorhighlight = "# cccccc"
The background color of the selected text. The default color is blue.
Android: textcolorhint = "# FFFF00"
Set the text color of the prompt information. The default color is gray.
Android: textscalex = "1.5"
Control the spacing between words
Android: Typeface = "monospace"
Font, normal, SANS, Serif, monospace
Android: Background = "@ null"
Space background. This field does not exist. It is transparent.
Android: layout_weight = "1"
Weight: controls the status between controls. It is useful when the control controls are displayed.
Android: textappearance = "? Android: ATTR/textappearancelargeinverse"


Edittext always does not pop up the software keyboard


1. The edittext keyboard is not displayed by default.
Method 1:
In androidmainfest. XML, select the activity and set the windowsoftinputmode attribute to adjustunspecified | statehidden.
Example: <activity Android: Name = ". Main"
Android: Label = "@ string/app_name"
Android: windowsoftinputmode = "adjustunspecified | statehidden"
Android: configchanges = "orientation | keyboardhidden">
<Action Android: Name = "android. Intent. Action. Main"/>
<Category Android: Name = "android. Intent. Category. launcher"/>
Method 2:
Defocus edittext. Use the clearfocus method of edittext.
For example, edittext edit = (edittext) findviewbyid (R. Id. Edit );
Edit. clearfocus ();
Method 3:
Force hide Android Input Method window
For example, edittext edit = (edittext) findviewbyid (R. Id. Edit );
Inputmethodmanager Imm = (inputmethodmanager) getsystemservice (context. input_method_service );
Imm. hidesoftinputfromwindow (edit. getwindowtoken (), 0 );

2. edittext always does not bring up the software keyboard
Example: edittext edit = (edittext) findviewbyid (R. Id. Edit );
Edit. setinputtype (inputtype. type_null );

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.