日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【鸿蒙 HarmonyOS】UI 组件 ( 文本输入框 TextField 组件 )

發布時間:2025/6/17 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【鸿蒙 HarmonyOS】UI 组件 ( 文本输入框 TextField 组件 ) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • 一、布局中設置 TextField 組件
  • 二、代碼中獲取并設置 TextField 組件





一、布局中設置 TextField 組件



TextField 組件是文本輸入框 , 允許用戶在界面中輸入指定的文字信息 ;

布局文件中配置 TextField 組件 :

<?xml version="1.0" encoding="utf-8"?> <DirectionalLayoutxmlns:ohos="http://schemas.huawei.com/res/ohos"ohos:height="match_parent"ohos:width="match_parent"ohos:orientation="vertical"><!-- 輸入框組件 --><TextFieldohos:id="$+id:textfield"ohos:height="match_content"ohos:width="match_parent"ohos:layout_alignment="horizontal_center"ohos:text="Hello World"ohos:text_size="50"ohos:text_input_type="pattern_number"/></DirectionalLayout>

其中 ohos:text_input_type=“pattern_number” 是配置輸入的類型 , 這里是輸入數字 ;


顯示效果 : 剛進入界面時效果與 Text 組件相同 , 但是點擊后 , 會顯示光標 , 并彈出輸入鍵盤 ;

剛進入界面時 :

點擊后效果 : 彈出軟鍵盤 ;





二、代碼中獲取并設置 TextField 組件



簡單展示一下獲取組件 , 并設置其顯示文本 ;

package com.example.textfield.slice;import com.example.textfield.ResourceTable; import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.agp.components.TextField;public class MainAbilitySlice extends AbilitySlice {@Overridepublic void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_main);// 獲取布局文件中的 TextField 組件TextField textField = (TextField) findComponentById(ResourceTable.Id_textfield);// 設置默認顯示的內容textField.setText("請輸入手機號 : ");}@Overridepublic void onActive() {super.onActive();}@Overridepublic void onForeground(Intent intent) {super.onForeground(intent);} }

運行效果 :

總結

以上是生活随笔為你收集整理的【鸿蒙 HarmonyOS】UI 组件 ( 文本输入框 TextField 组件 )的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。