女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

HarmonyOS系統(tǒng)TextField組件基本用法

電子發(fā)燒友論壇 ? 來源:電子發(fā)燒友論壇 ? 作者:兮動人 ? 2021-10-09 09:18 ? 次閱讀

1. TextField組件基本用法

組件說明:

是Text的子類,用來進行用戶輸入數(shù)據(jù)的

常見屬性:

5e2291ba-2381-11ec-82a8-dac502259ad0.png

《TextField ohos:id=“$+id:text” ohos:height=“50vp” ohos:width=“319vp” ohos:background_element=“#FFFFFF” ohos:hint=“請輸入信息” ohos:layout_alignment=“horizontal_center” ohos:text_alignment=“center” ohos:text_color=“#999999” ohos:text_size=“17fp” ohos:top_margin=“100vp”/》

2. TextField案例——獲取文本輸入框中的內(nèi)容并進行Toast提示

通過TextField獲取文本輸入框中的內(nèi)容并進行Toast提示

新建項目:TextFieldApplication

ability_main

《?xml version=“1.0” encoding=“utf-8”?》《DirectionalLayout xmlns:ohos=“http://schemas.huawei.com/res/ohos” ohos:height=“match_parent” ohos:width=“match_parent” ohos:background_element=“#F2F2F2” ohos:orientation=“vertical”》

《TextField ohos:id=“$+id:text” ohos:height=“50vp” ohos:width=“319vp” ohos:background_element=“#FFFFFF” ohos:hint=“請輸入信息” ohos:layout_alignment=“horizontal_center” ohos:text_alignment=“center” ohos:text_color=“#999999” ohos:text_size=“17fp” ohos:top_margin=“100vp”/》

《Button ohos:id=“$+id:but” ohos:height=“47vp” ohos:width=“319vp” ohos:background_element=“#21a8FD” ohos:layout_alignment=“center” ohos:text=“獲取信息” ohos:text_alignment=“center” ohos:text_color=“#FEFEFE” ohos:text_size=“24vp” ohos:top_margin=“77vp”/》

《/DirectionalLayout》

因為要在 onClick 方法中用到 TextField 和 Button 這兩個組件,所以要把這兩個組件移到成員位置,使其成為成員變量后,onClick 方法才能訪問的到

MainAbilitySlice

package com.xdr630.textfieldapplication.slice;

import com.xdr630.textfieldapplication.ResourceTable;import ohos.aafwk.ability.AbilitySlice;import ohos.aafwk.content.Intent;import ohos.agp.components.Button;import ohos.agp.components.Component;import ohos.agp.components.TextField;import ohos.agp.utils.LayoutAlignment;import ohos.agp.window.dialog.ToastDialog;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {

TextField tf; Button but;

@Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_main);

//1.找到文本組件框?qū)ο?tf = (TextField) findComponentById(ResourceTable.Id_text); //找到按鈕組件對象 but = (Button) findComponentById(ResourceTable.Id_but);

//2.給按鈕綁定點擊事件 //當(dāng)點擊了按鈕之后,就要獲取文本輸入框的內(nèi)容 but.setClickedListener(this);

}

@Override public void onActive() { super.onActive(); }

@Override public void onForeground(Intent intent) { super.onForeground(intent); }

@Override public void onClick(Component component) { //當(dāng)點擊了按鈕之后,獲取文本輸入框的內(nèi)容 String message = tf.getText(); //利用一個Toast將信息彈出 ToastDialog td = new ToastDialog(this); //大小不用設(shè)置,默認(rèn)是包裹內(nèi)容的 //自動關(guān)閉不用設(shè)置,默認(rèn)到了時間之后就自動關(guān)閉 //默認(rèn)持續(xù)時間是 2秒

//設(shè)置Toast的背景 td.setTransparent(true); //位置(默認(rèn)居中) td.setAlignment(LayoutAlignment.BOTTOM); //設(shè)置一個偏移 td.setOffset(0,200); //設(shè)置Toast內(nèi)容 td.setText(message); //讓Toast出現(xiàn) td.show(); }}

運行:

3. TextField組件高級用法

3.1 密碼的密文展示

當(dāng)輸入密碼的時候會變成密文展示

ohos:text_input_type=“pattern_password”:表示輸入的密碼以密文的方式顯示

基本使用:

《?xml version=“1.0” encoding=“utf-8”?》《DirectionalLayout xmlns:ohos=“http://schemas.huawei.com/res/ohos” ohos:height=“match_parent” ohos:width=“match_parent” ohos:orientation=“vertical” ohos:background_element=“#F2F2F2”》

《TextField ohos:height=“50vp” ohos:width=“319vp” ohos:hint=“請輸入信息” ohos:text_size=“17fp” ohos:hint_color=“#999999” ohos:text_alignment=“center” ohos:top_margin=“100vp” ohos:layout_alignment=“horizontal_center” ohos:background_element=“#FFFFFF” ohos:text_input_type=“pattern_password”/》

《/DirectionalLayout》

3.2 基線的設(shè)置

有的時候文本輸入框并不是一個框,而是下面有一條橫線,這條線華為官方叫做 基線

把文本輸入框使用橫線表示,在上面加上一條基線,把輸入框的背景顏色去掉

《TextField ohos:height=“50vp” ohos:width=“319vp” ohos:hint=“請輸入信息” ohos:text_size=“17fp” ohos:hint_color=“#999999” ohos:text_alignment=“center” ohos:top_margin=“100vp” ohos:layout_alignment=“horizontal_center” ohos:text_input_type=“pattern_password” ohos:basement=“#000000” /》

如果以后看到一條基線,然后在輸入一些數(shù)字信息,這還是 TextField 文本輸入框組件,只不過是背景色沒有設(shè)置,讓它跟布局的顏色一致了,看不到背景而已

3.3 氣泡的設(shè)置

當(dāng)用鼠標(biāo)長按選中輸入的內(nèi)容后,就會選中內(nèi)容,前面的光標(biāo)和后面的光標(biāo),以及中間選中的內(nèi)容顏色會改變,華為官方給前、后的光標(biāo),以及沒有選中內(nèi)容狀態(tài)下出現(xiàn)的小氣球取名為氣泡

《TextField ohos:height=“50vp” ohos:width=“319vp” ohos:hint=“請輸入信息” ohos:text_size=“17fp” ohos:hint_color=“#999999” ohos:text_alignment=“center” ohos:top_margin=“100vp” ohos:layout_alignment=“horizontal_center” ohos:basement=“#000000” /》

可以設(shè)置左邊、右邊,以及沒有選中情況下的氣泡

氣泡的圖片、顏色都是可以自定義的

以下用到的圖片可自取:

https://www.aliyundrive.com/s/wT22d1Vb1BV

把左、右,以及中間沒有選中的氣泡圖片復(fù)制到 media 文件夾下

《TextField ohos:height=“50vp” ohos:width=“319vp” ohos:hint=“請輸入信息” ohos:text_size=“17fp” ohos:hint_color=“#999999” ohos:text_alignment=“center” ohos:top_margin=“100vp” ohos:layout_alignment=“horizontal_center” ohos:basement=“#000000” ohos:element_selection_left_bubble=“$media:left” ohos:element_selection_right_bubble=“$media:right” ohos:element_cursor_bubble=“$media:bubble” ohos:selection_color=“#FF0000” /》

ohos:element_selection_left_bubble、ohos:element_selection_right_bubble分別設(shè)置左右氣泡顯示的圖片

ohos:element_cursor_bubble:設(shè)置沒有選中時的氣泡圖片

ohos:selection_color:設(shè)置選中時內(nèi)容的顏色

運行:

4. TextField案例——長按查看密碼明文

在一些APP中,登錄界面密碼輸入框那里有個小眼睛,按住小眼睛后就可以看到密碼的明文展示,松開小眼睛又恢復(fù)到密文狀態(tài)了

把“小眼睛”改成Button組件,實現(xiàn)的邏輯原理也是一樣的

需求分析:

按住按鈕不松,將輸入框中的密碼變成明文

松開按鈕之后,輸入框中的密碼變回密文

新建項目:TextFieldApplication3

ability_main

《?xml version=“1.0” encoding=“utf-8”?》《DirectionalLayout xmlns:ohos=“http://schemas.huawei.com/res/ohos” ohos:height=“match_parent” ohos:width=“match_parent” ohos:orientation=“vertical” ohos:background_element=“#F2F2F2” 》

《TextField ohos:id=“$+id:text” ohos:height=“50vp” ohos:width=“319vp” ohos:hint=“請輸入密碼” ohos:text_size=“17fp” ohos:hint_color=“#999999” ohos:text_alignment=“center” ohos:top_margin=“100vp” ohos:layout_alignment=“horizontal_center” ohos:background_element=“#FFFFFF” ohos:text_input_type=“pattern_password”/》 《Button ohos:id=“$+id:but” ohos:height=“47vp” ohos:width=“319vp” ohos:text=“查看密碼” ohos:text_size=“24vp” ohos:text_color=“#FEFEFE” ohos:text_alignment=“center” ohos:background_element=“#21a8FD” ohos:top_margin=“77vp” ohos:layout_alignment=“center”/》

《/DirectionalLayout》

MainAbilitySlice

package com.xdr630.textfieldapplication3.slice;

import com.xdr630.textfieldapplication3.ResourceTable;import ohos.aafwk.ability.AbilitySlice;import ohos.aafwk.content.Intent;import ohos.agp.components.Button;import ohos.agp.components.Component;import ohos.agp.components.InputAttribute;import ohos.agp.components.TextField;import ohos.multimodalinput.event.TouchEvent;

public class MainAbilitySlice extends AbilitySlice implements Component.TouchEventListener {

TextField tf;

@Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_main);

//1.找到兩個組件對象 tf = (TextField) findComponentById(ResourceTable.Id_text); Button but = (Button) findComponentById(ResourceTable.Id_but);

//2.要給按鈕綁定一個觸摸事件 //因為在觸摸事件中,才能獲取到按下不松或松開 //單擊事件——只能捕獲到點擊了一下 but.setTouchEventListener(this);

}

@Override public void onActive() { super.onActive(); }

@Override public void onForeground(Intent intent) { super.onForeground(intent); }

@Override //參數(shù)一:現(xiàn)在觸摸的按鈕 //參數(shù)二:動作對象 public boolean onTouchEvent(Component component, TouchEvent touchEvent) { int action = touchEvent.getAction();

if (action == TouchEvent.PRIMARY_POINT_DOWN){//表示按下不松的時候 //當(dāng)按下不送的時候,將文本框中密碼變成明文 tf.setTextInputType(InputAttribute.PATTERN_NULL); }else if (action == TouchEvent.PRIMARY_POINT_UP){//表示松開的時候 //當(dāng)松開的時候,將文本框中的密碼變回密文 tf.setTextInputType(InputAttribute.PATTERN_PASSWORD); } //true:表示觸摸事件的后續(xù)動作還會進行觸發(fā) //false:表示觸摸事件只觸發(fā)第一個按下不松 return true; }}

運行:

5. TextField案例——搭建登錄界面

新建項目:TextFieldApplication4

細節(jié)說明:

Text文本(忘記密碼了?)組件默認(rèn)是左邊放置的,加上 ohos:layout_alignment=“right”就是右邊放置了,同時也給個ohos:right_margin=“20vp”和右邊的屏幕有些距離。如果ohos:layout_alignment=“right”屬性不寫,直接寫ohos:right_margin=“20vp,那么ohos:layout_alignment=”right“屬性就會失效,因為組件默認(rèn)是放在左邊的。

ability_main

《?xml version=”1.0“ encoding=”utf-8“?》《DirectionalLayout xmlns:ohos=”http://schemas.huawei.com/res/ohos“ ohos:height=”match_parent“ ohos:width=”match_parent“ ohos:orientation=”vertical“ ohos:background_element=”#F2F2F2“》

《TextField ohos:id=”$+id:username“ ohos:height=”50vp“ ohos:width=”319vp“ ohos:hint=”請輸入用戶名“ ohos:text_size=”17fp“ ohos:hint_color=”#999999“ ohos:text_alignment=”center“ ohos:top_margin=”100vp“ ohos:layout_alignment=”horizontal_center“ ohos:background_element=”#FFFFFF“/》

《TextField ohos:id=”$+id:password“ ohos:height=”50vp“ ohos:width=”319vp“ ohos:hint=”請輸入密碼“ ohos:text_size=”17fp“ ohos:hint_color=”#999999“ ohos:text_alignment=”center“ ohos:top_margin=”10vp“ ohos:layout_alignment=”horizontal_center“ ohos:background_element=”#FFFFFF“ ohos:text_input_type=”pattern_password“/》 《Text ohos:height=”match_content“ ohos:width=”match_content“ ohos:text=”忘記密碼了?“ ohos:text_size=”17fp“ ohos:text_color=”#979797“ ohos:top_margin=”13vp“ ohos:layout_alignment=”right“ ohos:right_margin=”20vp“/》 《Button ohos:height=”47vp“ ohos:width=”319vp“ ohos:text=”登錄“ ohos:text_size=”24fp“ ohos:text_color=”#FEFEFE“ ohos:text_alignment=”center“ ohos:background_element=”#21a8FD“ ohos:top_margin=”77vp“ ohos:layout_alignment=”horizontal_center“/》

《Button ohos:height=”47vp“ ohos:width=”319vp“ ohos:text=”注冊“ ohos:text_size=”24fp“ ohos:text_color=”#FEFEFE“ ohos:text_alignment=”center“ ohos:background_element=”#21a8FD“ ohos:top_margin=”13vp“ ohos:layout_alignment=”horizontal_center“/》

《/DirectionalLayout》

責(zé)任編輯:haq

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 操作系統(tǒng)
    +關(guān)注

    關(guān)注

    37

    文章

    7061

    瀏覽量

    124884
  • 文本
    +關(guān)注

    關(guān)注

    0

    文章

    119

    瀏覽量

    17351
  • HarmonyOS
    +關(guān)注

    關(guān)注

    79

    文章

    2026

    瀏覽量

    32058

原文標(biāo)題:【鴻蒙實戰(zhàn)】HarmonyOS實戰(zhàn)——TextField文本輸入框組件基本使用

文章出處:【微信號:gh_9b9470648b3c,微信公眾號:電子發(fā)燒友論壇】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏

    評論

    相關(guān)推薦
    熱點推薦

    UIAbility組件基本用法說明

    UIAbility組件基本用法 UIAbility組件的基本用法包括:指定UIAbility的啟動頁面以及獲取UIAbility的上下文UIAbilityContext。 指定UIA
    發(fā)表于 05-16 06:32

    harmony OS NEXT-Navagation基本用法

    # Navagation基本用法 > Navigation組件是路由導(dǎo)航的根視圖容器,一般作為Page頁面的根容器使用,其內(nèi)部默認(rèn)包含了標(biāo)題欄,內(nèi)容欄和公工具欄,其中內(nèi)容區(qū)默認(rèn)首頁顯示導(dǎo)航內(nèi)容
    的頭像 發(fā)表于 04-27 17:39 ?166次閱讀

    KaihongOS操作系統(tǒng):Button按鈕組件介紹

    Button 按鈕組件,可快速創(chuàng)建不同樣式的按鈕。 常用接口 Button Button(options: ButtonOptions) 創(chuàng)建可以包含單個子組件的按鈕。 參數(shù): 參數(shù)名類型必填
    發(fā)表于 04-25 07:09

    HarmonyOS Next V2 @Local 和@Param

    HarmonyOS Next V2 @Local 和@Param @Local 背景 @Local 是 harmony 應(yīng)用開發(fā)中的 v2 版本中 對標(biāo)**@State**的狀態(tài)管理修飾器,它解決了
    的頭像 發(fā)表于 04-02 18:27 ?262次閱讀
    <b class='flag-5'>HarmonyOS</b> Next V2 @Local 和@Param

    HarmonyOS Next V2 @Event

    HarmonyOS Next V2 @Event 背景 在上一節(jié)中,我們針對父子組件,講了關(guān)于傳遞數(shù)據(jù)的知識。我們了解到 @Local 是管理自己內(nèi)部的數(shù)據(jù)的, @Param 是負責(zé)接收父組件的數(shù)據(jù)
    的頭像 發(fā)表于 03-31 09:42 ?237次閱讀

    「極速探索HarmonyOS NEXT 」閱讀體驗】+Web組件

    ,則源于web開發(fā)。盡管Web應(yīng)用在性能上略遜一籌,但由于其龐大的用戶使用基數(shù),在諸多場景下仍不可或缺。 在應(yīng)用中顯示 Web 頁面 在開發(fā)中使用 Web組件主要分為兩種方式: 通過 Web 組件顯示
    發(fā)表于 03-10 10:39

    解決HarmonyOS應(yīng)用中Image組件白塊問題的有效方案

    HarmonyOS應(yīng)用開發(fā)過程中,通過Image組件加載網(wǎng)絡(luò)圖片時,通常會經(jīng)歷四個關(guān)鍵階段:組件創(chuàng)建、圖片資源下載、圖片解碼和刷新。當(dāng)加載的圖片資源過大時,Image組件會等待圖片數(shù)
    的頭像 發(fā)表于 02-17 10:08 ?903次閱讀
    解決<b class='flag-5'>HarmonyOS</b>應(yīng)用中Image<b class='flag-5'>組件</b>白塊問題的有效方案

    華為發(fā)布鴻蒙HarmonyOS 5.0.2 Release

    華為鴻蒙HarmonyOS 5.0.2 Release于1月22日在華為開發(fā)者官方正式發(fā)布。HarmonyOS 5.0.2 Release在HarmonyOS 5.0.2 Beta1的基礎(chǔ)上,進行了
    的頭像 發(fā)表于 01-23 16:17 ?1285次閱讀

    HarmonyOS Web頁面加載的原理和優(yōu)化方法

    在移動互聯(lián)網(wǎng)時代,應(yīng)用的頁面渲染速度對于用戶體驗至關(guān)重要。相對于原生頁面,Web頁面的性能存在多方面的技術(shù)挑戰(zhàn)。本文以HarmonyOS的ArkWeb組件為基礎(chǔ),介紹了Web頁面加載中的影響因素以及對應(yīng)的優(yōu)化方案。
    的頭像 發(fā)表于 12-05 15:14 ?903次閱讀
    <b class='flag-5'>HarmonyOS</b> Web頁面加載的原理和優(yōu)化方法

    AWTK 最新動態(tài):支持鴻蒙系統(tǒng)(HarmonyOS Next)

    導(dǎo)讀HarmonyOS是全球第三大移動操作系統(tǒng),有巨大的市場潛力,在國產(chǎn)替代的背景下,機會多多,AWTK支持HarmonyOS,讓AWTK開發(fā)者也能享受HarmonyOS生態(tài)的紅利。A
    的頭像 發(fā)表于 11-06 08:03 ?681次閱讀
    AWTK 最新動態(tài):支持鴻蒙<b class='flag-5'>系統(tǒng)</b>(<b class='flag-5'>HarmonyOS</b> Next)

    華為HarmonyOS NEXT 10月8日開啟公測

    華為宣布,萬眾矚目的HarmonyOS NEXT操作系統(tǒng)將于10月8日正式開啟公測,標(biāo)志著這一創(chuàng)新力作即將與廣大用戶見面。HarmonyOS NEXT作為華為自研操作系統(tǒng)的最新成果,不
    的頭像 發(fā)表于 09-24 15:41 ?1242次閱讀
    華為<b class='flag-5'>HarmonyOS</b> NEXT 10月8日開啟公測

    華為“純血”鴻蒙系統(tǒng) HarmonyOS NEXT 將于9月底推出正式版

    HarmonyOS NEXT 將于今年 9 月底推出正式版本。 “從發(fā)布第一個版本到今年的 9 月份,這個(9 月)月底我們會正式發(fā)布 HarmonyOS NEXT,這一版本是完全獨立開發(fā)、獨立自主的,而且是不兼容安卓系統(tǒng)。”
    的頭像 發(fā)表于 09-14 14:27 ?2154次閱讀

    HarmonyOS NEXT Developer Beta1最新術(shù)語表

    HAP中。 ANS Advanced Notification Service,通知增強服務(wù),是HarmonyOS中負責(zé)處理通知的訂閱、發(fā)布和更新等操作的系統(tǒng)服務(wù)。 Atomic Service,元
    發(fā)表于 06-27 16:16

    國產(chǎn)系統(tǒng)重要突破!深開鴻KaihongOS率先連接HarmonyOS Next,實現(xiàn)跨生態(tài)互聯(lián)

    6月21日,華為開發(fā)者大會2024上正式發(fā)布了全新的操作系統(tǒng)HarmonyOSNext,發(fā)布了全新的分布式軟總線、全新星盾安全架構(gòu)和系統(tǒng)級原生智能,探討最新技術(shù)動態(tài)與行業(yè)趨勢。深開鴻作為華為堅定
    的頭像 發(fā)表于 06-25 11:24 ?970次閱讀
    國產(chǎn)<b class='flag-5'>系統(tǒng)</b>重要突破!深開鴻KaihongOS率先連接<b class='flag-5'>HarmonyOS</b> Next,實現(xiàn)跨生態(tài)互聯(lián)

    鴻蒙Ability Kit(程序框架服務(wù))【UIAbility組件基本用法

    UIAbility組件的基本用法包括:指定UIAbility的啟動頁面以及獲取UIAbility的上下文[UIAbilityContext]。
    的頭像 發(fā)表于 06-06 11:02 ?810次閱讀
    鴻蒙Ability Kit(程序框架服務(wù))【UIAbility<b class='flag-5'>組件</b>基本<b class='flag-5'>用法</b>】