Specifying the Input Method Type | Android Developers - M.I.T.

文章推薦指數: 80 %
投票人數:10人

Specify the Keyboard Type Quicknav Quicknav Design Develop Distribute GooglePlayDeveloperConsole AndroidDevelopersBlog AboutAndroid Android.com AndroidDevelopers AndroidOpenSourceProject close GetStarted Style Patterns BuildingBlocks Downloads Videos Training APIGuides Reference Tools GettheSDK GoogleServices GooglePlay Publishing Promoting AppQuality Spotlight OpenDistribution Results Loading... Training APIGuides Reference Tools GoogleServices totop GettingStarted BuildingYourFirstApp CreatinganAndroidProject RunningYourApplication BuildingaSimpleUserInterface StartingAnotherActivity ManagingtheActivityLifecycle StartinganActivity PausingandResuminganActivity StoppingandRestartinganActivity RecreatinganActivity SupportingDifferentDevices SupportingDifferentLanguages SupportingDifferentScreens SupportingDifferentPlatformVersions BuildingaDynamicUIwithFragments UsingtheSupportLibrary CreatingaFragment BuildingaFlexibleUI CommunicatingwithOtherFragments SavingData SavingKey-ValueSets SavingFiles SavingDatainSQLDatabases InteractingwithOtherApps SendingtheUsertoAnotherApp GettingaResultfromtheActivity AllowingOtherAppstoStartYourActivity SharingContent SendingContenttoOtherApps ReceivingContentfromOtherApps AddinganEasyShareAction BuildingAppswithMultimedia ManagingAudioPlayback ControllingYourApp'sVolumeandPlayback ManagingAudioFocus DealingwithAudioOutputHardware CapturingPhotos TakingPhotosSimply RecordingVideosSimply ControllingtheCamera BuildingAppswithGraphics&Animation DisplayingBitmapsEfficiently LoadingLargeBitmapsEfficiently ProcessingBitmapsOfftheUIThread CachingBitmaps DisplayingBitmapsinYourUI DisplayingGraphicswithOpenGLES BuildinganOpenGLESEnvironment DefiningShapes DrawingShapes ApplyingProjectionandCameraViews AddingMotion RespondingtoTouchEvents AddingAnimations CrossfadingTwoViews UsingViewPagerforScreenSlide DisplayingCardFlipAnimations ZoomingaView AnimatingLayoutChanges BuildingAppswith Connectivity&theCloud ConnectingDevicesWirelessly UsingNetworkServiceDiscovery ConnectingwithWi-FiDirect UsingWi-FiDirectforServiceDiscovery PerformingNetworkOperations ConnectingtotheNetwork ManagingNetworkUsage ParsingXMLData TransferringDataWithoutDrainingtheBattery OptimizingDownloadsforEfficientNetworkAccess MinimizingtheEffectofRegularUpdates RedundantDownloadsareRedundant ModifyingPatternsBasedontheConnectivityType SyncingtotheCloud UsingtheBackupAPI MakingtheMostofGoogleCloudMessaging BuildingAppswith UserInfo&Location RememberingUsers RememberingYourUser AuthenticatingtoOAuth2Services CreatingaCustomAccountType MakingYourAppLocationAware UsingtheLocationManager ObtainingtheCurrentLocation DisplayingaLocationAddress BestPracticesfor UserExperience&UI DesigningEffectiveNavigation PlanningScreensandTheirRelationships PlanningforMultipleTouchscreenSizes ProvidingDescendantandLateralNavigation ProvidingAncestralandTemporalNavigation PuttingitAllTogether:WireframingtheExampleApp ImplementingEffectiveNavigation ImplementingLateralNavigation ImplementingAncestralNavigation ImplementingTemporalNavigation ImplementingDescendantNavigation NotifyingtheUser BuildingaNotification PreservingNavigationwhenStartinganActivity UpdatingNotifications UsingBigViewStyles DisplayingProgressinaNotification AddingSearchFunctionality SettinguptheSearchInterface StoringandSearchingforData RemainingBackwardCompatible DesigningforMultipleScreens SupportingDifferentScreenSizes SupportingDifferentScreenDensities ImplementingAdaptiveUIFlows DesigningforTV OptimizingLayoutsforTV OptimizingNavigationforTV HandlingFeaturesNotSupportedonTV CreatingCustomViews CreatingaCustomViewClass ImplementingCustomDrawing MakingtheViewInteractive OptimizingtheView CreatingBackward-CompatibleUIs AbstractingtheNewAPIs ProxyingtotheNewAPIs CreatinganImplementationwithOlderAPIs UsingtheVersion-AwareComponent ImplementingAccessibility DevelopingAccessibleApplications DevelopingAccessibilityServices BestPracticesfor UserInput UsingTouchGestures DetectingCommonGestures TrackingMovement AnimatingaScrollGesture HandlingMulti-TouchGestures DraggingandScaling ManagingTouchEventsinaViewGroup HandlingKeyboardInput SpecifyingtheInputMethodType HandlingInputMethodVisibility SupportingKeyboardNavigation HandlingKeyboardActions BestPracticesfor Performance PerformanceTips ImprovingLayoutPerformance OptimizingLayoutHierarchies Re-usingLayoutswith LoadingViewsOnDemand MakingListViewScrollingSmooth RunninginaBackgroundService CreatingaBackgroundService SendingWorkRequeststotheBackgroundService ReportingWorkStatus LoadingDataintheBackground RunningaQuerywithaCursorLoader HandlingtheResults OptimizingBatteryLife MonitoringtheBatteryLevelandChargingState DeterminingandMonitoringtheDockingStateandType DeterminingandMonitoringtheConnectivityStatus ManipulatingBroadcastReceiversOnDemand SendingOperationstoMultipleThreads SpecifyingtheCodetoRunonaThread CreatingaManagerforMultipleThreads RunningCodeonaThreadPoolThread CommunicatingwiththeUIThread KeepingYourAppResponsive JNITips SMPPrimerforAndroid BestPracticesfor Security&Privacy SecurityTips DevelopingforEnterprise EnhancingSecuritywithDeviceManagementPolicies UsingGooglePlayto Distribute&Monetize SellingIn-appProducts PreparingYourApp EstablishingProductsforSale PurchasingProducts TestingYourApp MaintainingMultipleAPKs CreatingMultipleAPKsforDifferentAPILevels CreatingMultipleAPKsforDifferentScreenSizes CreatingMultipleAPKsforDifferentGLTextures CreatingMultipleAPKswith2+Dimensions MonetizingYourApp AdvertisingwithoutCompromisingUserExperience SpecifyingtheInputMethodType Previous Next Getstarted Thislessonteachesyouto SpecifytheKeyboardType EnableSpellingSuggestionsandOtherBehaviors SpecifytheInputMethodAction Youshouldalsoread TextFields Everytextfieldexpectsacertaintypeoftextinput,suchasan emailaddress,phonenumber,orjustplaintext.Soit'simportant thatyouspecifytheinputtypeforeachtextfieldinyourapp sothesystemdisplaystheappropriatesoftinputmethod(suchasanon-screenkeyboard). Beyondthetypeofbuttonsavailablewithaninputmethod,youshouldspecify behaviorssuchaswhethertheinputmethodprovidesspellingsuggestions, capitalizesnewsentences,andreplacesthecarriagereturnbuttonwithan actionbuttonsuchasaDoneorNext. Thislessonshowshowtospecifythesecharacteristics. SpecifytheKeyboardType Youshouldalwaysdeclaretheinputmethodforyourtextfieldsbyadding theandroid:inputTypeattributetotheelement. Figure1.Thephoneinputtype. Forexample,ifyou'dlikeaninputmethodforenteringaphonenumber, usethe"phone"value: Figure2.ThetextPasswordinputtype. Orifthetextfieldisforapassword,usethe"textPassword"value sothetextfieldconcealstheuser'sinput: Thereareseveralpossiblevaluesdocumentedwiththe android:inputTypeattributeand someofthevaluescanbecombinedtospecifytheinputmethod appearanceandadditionalbehaviors. EnableSpellingSuggestionsandOtherBehaviors Figure3.AddingtextAutoCorrect providesauto-correctionformisspellings. Theandroid:inputTypeattributeallowsyoutospecifyvariousbehaviorsforthe inputmethod.Mostimportantly,ifyourtextfieldisintendedforbasictextinput(such asforatextmessage),youshouldenableautospellingcorrectionwiththe "textAutoCorrect"value. Youcancombinedifferentbehaviorsandinputmethodstyleswiththe android:inputTypeattribute.Forexample, here'showtocreateatextfieldthatcapitalizesthefirstwordofasentence andalsoauto-correctsmisspellings: SpecifytheInputMethodAction Mostsoftinputmethodsprovideauseractionbuttoninthe bottomcornerthat'sappropriateforthecurrenttextfield. Bydefault,thesystemusesthisbuttonforeitheraNextor Doneactionunlessyourtextfieldallowsmulti-linetext(suchaswithandroid:inputType="textMultiLine"),inwhichcasetheactionbuttonisacarriagereturn. However,youcanspecifyadditionalactionsthatmightbemoreappropriateforyour textfield,suchasSendorGo. Tospecifythekeyboardactionbutton,usetheandroid:imeOptionsattributewithanactionvaluesuchas"actionSend"or "actionSearch".Forexample: Figure4.TheSendbuttonappearswhenyoudeclare android:imeOptions="actionSend". Youcanthenlistenforpressesontheactionbuttonbydefininga TextView.OnEditorActionListenerfortheEditText element.Inyourlistener,respondtotheappropriateIMEactionIDdefinedinthe EditorInfoclass,suchas IME_ACTION_SEND.Forexample: EditTexteditText=(EditText)findViewById(R.id.search); editText.setOnEditorActionListener(newOnEditorActionListener(){ @Override publicbooleanonEditorAction(TextViewv,intactionId,KeyEventevent){ booleanhandled=false; if(actionId==EditorInfo.IME_ACTION_SEND){ sendMessage(); handled=true; } returnhandled; } }); Previous Next Nextclass: Exceptasnoted,thiscontentis licensedunder CreativeCommonsAttribution2.5.Fordetailsand restrictions,seetheContent License. AboutAndroid  |  Legal  |  Support



請為這篇文章評分?