温州网站建设技术托管,广州番禺区美食攻略,多语言网站建设,网站托管运营所需资料13.鸿蒙HarmonyOS App(JAVA)文本框按钮点击提示
点击按钮触发组件状态#xff0c;点击改变颜色
文本框组件#xff0c;文本居中#xff0c;斜体#xff0c;左右对齐#xff0c;点击显示提示信息
Button button(Button) findComponentById(ResourceTable.Id_btn_1);
but…
13.鸿蒙HarmonyOS App(JAVA)文本框按钮点击提示
点击按钮触发组件状态点击改变颜色
文本框组件文本居中斜体左右对齐点击显示提示信息
Button button(Button) findComponentById(ResourceTable.Id_btn_1);
button.setClickedListener(new Component.ClickedListener() {Overridepublic void onClick(Component component) {new ToastDialog(getContext()).setText(登录信息提示).setAlignment(LayoutAlignment.CENTER).show();}
});
字体设置
Text text_bold (Text) findComponentById(ResourceTable.Id_text_bold);
text_bold.setFont(Font.DEFAULT_BOLD);
text_bold.setTextColor(Color.BLUE);
text,textfiled控件
编辑器动作 TextField textField (TextField) findComponentById(ResourceTable.Id_text_filed_user_name);// textField.setInputMethodOption(InputAttribute.ENTER_KEY_TYPE_SEARCH);// textField.setInputMethodOption(InputAttribute.ENTER_KEY_TYPE_GO);
// textField.setInputMethodOption(InputAttribute.ENTER_KEY_TYPE_SEND);textField.setInputMethodOption(InputAttribute.ENTER_KEY_TYPE_UNSPECIFIED); MainAbilitySlice
package com.example.myapplication.slice;import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.text.Font;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;public class MainAbilitySlice extends AbilitySlice {Overridepublic void onStart(Intent intent) {super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_main);Text text_bold (Text) findComponentById(ResourceTable.Id_text_bold);text_bold.setFont(Font.DEFAULT_BOLD);text_bold.setTextColor(Color.BLUE);TextField textField (TextField) findComponentById(ResourceTable.Id_text_filed_user_name);textField.setInputMethodOption(InputAttribute.ENTER_KEY_TYPE_SEARCH);// textField.setInputMethodOption(InputAttribute.ENTER_KEY_TYPE_GO);// textField.setInputMethodOption(InputAttribute.ENTER_KEY_TYPE_SEND);// textField.setInputMethodOption(InputAttribute.ENTER_KEY_TYPE_UNSPECIFIED);Button button(Button) findComponentById(ResourceTable.Id_btn_1);button.setClickedListener(new Component.ClickedListener() {Overridepublic void onClick(Component component) {new ToastDialog(getContext()).setText(登录信息提示).setAlignment(LayoutAlignment.CENTER).show();}});}Overridepublic void onActive() {super.onActive();}Overridepublic void onForeground(Intent intent) {super.onForeground(intent);}
}layout
ability_main.xml
?xml version1.0 encodingutf-8?
DirectionalLayoutxmlns:ohoshttp://schemas.huawei.com/res/ohosohos:heightmatch_parentohos:widthmatch_parentohos:alignmentcenterohos:orientationverticalTextohos:id$id:text_user_nameohos:heightmatch_contentohos:width350vpohos:background_element$graphic:background_ability_mainohos:text用户名ohos:text_size40vp/TextFieldohos:id$id:text_filed_user_nameohos:heightmatch_contentohos:background_element#FC0A84EFohos:width350vpohos:hint请输入用户名ohos:margin2vpohos:text_size40vp/Textohos:id$id:text_passohos:heightmatch_contentohos:width350vpohos:background_element$graphic:background_ability_mainohos:text密码ohos:text_size40vp/TextFieldohos:id$id:text_filed_psohos:heightmatch_contentohos:background_element#FC0A84EFohos:width350vpohos:hint请输入密码ohos:text_input_typepattern_passwordohos:margin2vpohos:text_size40vp/Textohos:id$id:text_1ohos:heightmatch_contentohos:widthmatch_contentohos:background_element$graphic:btn_state_containerohos:layout_alignmenthorizontal_centerohos:text测试文本ohos:text_size40vp/Textohos:id$id:text_boldohos:heightmatch_contentohos:widthmatch_contentohos:background_element$graphic:background_ability_mainohos:layout_alignmenthorizontal_centerohos:text加粗文本ohos:text_size40vp/Textohos:id$id:text_xietiohos:heightmatch_contentohos:width390vpohos:background_element#FF84F136ohos:layout_alignmenthorizontal_centerohos:text斜体文本ohos:italictrueohos:text_size40vp/Textohos:id$id:text_2ohos:heightmatch_contentohos:width390vpohos:background_element$graphic:background_ability_mainohos:layout_alignmenthorizontal_centerohos:text左对齐ohos:text_alignmentleftohos:text_size40vp/Textohos:id$id:text_3ohos:heightmatch_contentohos:widthmatch_contentohos:background_element$graphic:background_ability_mainohos:layout_alignmenthorizontal_centerohos:text居中文本ohos:text_alignmentcenterohos:text_size40vp/Textohos:id$id:text_3aohos:heightmatch_contentohos:background_element#FC0A84EFohos:width390vpohos:text_alignmentrightohos:text右对齐文本ohos:margin2vpohos:text_size40vp/Textohos:id$id:text_3bohos:heightmatch_contentohos:widthmatch_contentohos:background_element$graphic:background_ability_mainohos:layout_alignmenthorizontal_centerohos:text多行文本1234567890多行文本多行文本多行文本多行文本多行文ohos:multiple_linestrueohos:text_size40vp/Buttonohos:id$id:btn_1ohos:heightmatch_contentohos:widthmatch_contentohos:background_element$graphic:btn_state_containerohos:layout_alignmenthorizontal_centerohos:text登录按钮ohos:text_size40vp//DirectionalLayout
graphic
btn_state_container.xml
?xml version1.0 encodingutf-8?
state-containerxmlns:ohoshttp://schemas.huawei.com/res/ohositem ohos:state component_state_pressed ohos:element #FF4286EE/!--按下切换到该状态 --item ohos:state component_state_hovered ohos:element #FF76EE42/!--触摸设备不会切换到该状态 --item ohos:state component_state_empty ohos:element #FF65D9EE/!--默认状态 --item ohos:state component_state_selected ohos:element #FFE7F14A/!--默认状态 --
/state-container