13.鸿蒙HarmonyOS App(JAVA)文本框组件按钮点击提示

13.鸿蒙HarmonyOS App(JAVA)文本框组件按钮点击提示_第1张图片

13.鸿蒙HarmonyOS App(JAVA)文本框按钮点击提示

点击按钮触发组件状态,点击改变颜色

文本框组件,文本居中,斜体,左右对齐,点击显示提示信息

Button button=(Button) findComponentById(ResourceTable.Id_btn_1);
button.setClickedListener(new Component.ClickedListener() {
    @Override
    public 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);

13.鸿蒙HarmonyOS App(JAVA)文本框组件按钮点击提示_第2张图片

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 {
    @Override
    public 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() {
            @Override
            public void onClick(Component component) {
                new ToastDialog(getContext())
                        .setText("登录信息提示")
                        .setAlignment(LayoutAlignment.CENTER)
                        .show();


            }
        });

    }

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

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

 layout 

ability_main.xml




        
        

    
    
    
    
    
    
    
    
    
    

graphic

btn_state_container.xml



    
    
    
    

你可能感兴趣的:(harmonyos,华为)