Académique Documents
Professionnel Documents
Culture Documents
$QGURLG(GLW7H[W&RQWURO
ANDROIDEDITTEXTCONTROL
http://www.tutorialspoint.com/android/android_edittext_control.htm
Copyrighttutorialspoint.com
AEditTextisanoverlayoverTextViewthatconfiguresitselftobeeditable.Itisthe
predefinedsubclassofTextViewthatincludesricheditingcapabilities.
Stylesofedittext
EditTextAttributes
FollowingaretheimportantattributesrelatedtoEditTextcontrol.YoucancheckAndroidofficial
documentationforcompletelistofattributesandrelatedmethodswhichyoucanusetochangethese
attributesareruntime.
Inheritedfromandroid.widget.TextViewClass
Attribute
Description
android:autoText
Ifset,specifiesthatthisTextViewhasatextualinputmethodand
automaticallycorrectssomecommonspellingerrors.
android:drawableBottom
Thisisthedrawabletobedrawnbelowthetext.
android:drawableRight
Thisisthedrawabletobedrawntotherightofthetext.
android:editable
Ifset,specifiesthatthisTextViewhasaninputmethod.
android:text
ThisistheTexttodisplay.
KWWSZZZWXWRULDOVSRLQWFRPFJLELQSULQWSDJHFJL
$QGURLG(GLW7H[W&RQWURO
Inheritedfromandroid.view.ViewClass
Attribute
Description
android:background
Thisisadrawabletouseasthebackground.
android:contentDescription
Thisdefinestextthatbrieflydescribescontentoftheview.
android:id
Thissuppliesanidentifiernameforthisview,
android:onClick
ThisisthenameofthemethodinthisView'scontexttoinvokewhen
theviewisclicked.
android:visibility
Thiscontrolstheinitialvisibilityoftheview.
Example
ThisexamplewilltakeyouthroughsimplestepstoshowhowtocreateyourownAndroidapplication
usingLinearLayoutandEditText.
Step
Description
YouwilluseAndroidstudioIDEtocreateanAndroidapplicationandnameitasdemounder
apackagecom.example.demoasexplainedintheHelloWorldExamplechapter.
Modifysrc/MainActivity.javafiletoaddaclickevent.
Modifythedefaultcontentofres/layout/activity_main.xmlfiletoincludeAndroidUI
control.
Definerequirednecessarystringconstantsinres/values/strings.xmlfile
RuntheapplicationtolaunchAndroidemulatorandverifytheresultofthechangesdonein
theapplication.
Followingisthecontentofthemodifiedmainactivityfile
src/com.example.demo/MainActivity.java.Thisfilecanincludeeachofthefundamentallifecycle
methods.
KWWSZZZWXWRULDOVSRLQWFRPFJLELQSULQWSDJHFJL
$QGURLG(GLW7H[W&RQWURO
Followingwillbethecontentofres/layout/activity_main.xmlfile
<RelativeLayout
>
<TextView
/>
<Button
KWWSZZZWXWRULDOVSRLQWFRPFJLELQSULQWSDJHFJL
$QGURLG(GLW7H[W&RQWURO
/>
<EditText
/>
</RelativeLayout>
Followingwillbethecontentofres/values/strings.xmltodefinethesenewconstants
FollowingisthedefaultcontentofAndroidManifest.xml
KWWSZZZWXWRULDOVSRLQWFRPFJLELQSULQWSDJHFJL
$QGURLG(GLW7H[W&RQWURO
Let'strytorunyourdemoapplication.IassumeyouhadcreatedyourAVDwhiledoingenvironment
setup.ToruntheappfromAndroidstudio,openoneofyourproject'sactivityfilesandclickRun
iconfromthetoolbar.AndroidStudioinstallstheapponyourAVDandstartsitandifeverythingisfine
withyoursetupandapplication,itwilldisplayfollowingEmulatorwindow
Exercise
IwillrecommendtotryaboveexamplewithdifferentattributesofEditTextinLayoutXMLfileaswell
atprogrammingtimetohavedifferentlookandfeeloftheEditText.Trytomakeiteditable,changeto
fontcolor,fontfamily,width,textSizeetcandseetheresult.Youcanalsotryaboveexamplewith
multipleEditTextcontrolsinoneactivity.
KWWSZZZWXWRULDOVSRLQWFRPFJLELQSULQWSDJHFJL