页面学习——鸿蒙登录页面设计

页面学习——鸿蒙登录页面设计

1.布局文件

<?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:alignment="vertical_center"
    ohos:background_element="$media:bg_login"
    ohos:orientation="vertical">

    <Text
        ohos:height="50vp"
        ohos:text_size="30vp"
        ohos:text="鸿蒙登录页面"
        ohos:text_alignment="center"
        ohos:text_weight="900"
        ohos:text_color="#FFFFFF"
        ohos:width="match_parent"/>

    <DirectionalLayout
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:background_element="$graphic:background_login_input"
        ohos:margin="20vp"
        ohos:orientation="horizontal"
        ohos:padding="10vp"
        >

        <Image
            ohos:height="40vp"
            ohos:width="40vp"
            ohos:image_src="$media:icon_username"
            ohos:left_margin="10vp"
            ohos:scale_x="0.5"
            ohos:scale_y="0.5"/>

        <TextField
            ohos:height="40vp"
            ohos:width="match_content"
            ohos:hint="请输入用户名"
            ohos:hint_color="#ffffff"
            ohos:left_margin="10vp"
            ohos:text_alignment="vertical_center"
            ohos:text_color="#ffffff"
            ohos:text_size="12fp"/>

    </DirectionalLayout>

    <DirectionalLayout
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:background_element="$graphic:background_login_input"
        ohos:margin="20vp"
        ohos:orientation="horizontal"
        ohos:padding="10vp"
        >


        <Image
            ohos:height="40vp"
            ohos:width="40vp"
            ohos:image_src="$media:icon_password"
            ohos:left_margin="10vp"
            ohos:scale_x="0.5"
            ohos:scale_y="0.5"/>

        <TextField
            ohos:height="40vp"
            ohos:width="match_content"
            ohos:hint="请输入密码"
            ohos:hint_color="#ffffff"
            ohos:left_margin="10vp"
            ohos:text_alignment="vertical_center"
            ohos:text_color="#ffffff"
            ohos:text_input_type="pattern_password"
            ohos:text_size="12fp"/>

    </DirectionalLayout>


    <Button
        ohos:id="$+id:loginButton"
        ohos:height="50vp"
        ohos:width="match_parent"
        ohos:background_element="$graphic:background_button"
        ohos:margin="20vp"
        ohos:text="登录"
        ohos:text_alignment="center"
        ohos:text_color="#FFFFFF"
        ohos:text_size="18vp"/>


</DirectionalLayout>
  1. 背景图
    background_login_input.xml
<?xml version="1.0" encoding="utf-8"?>

<shape
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:shape="rectangle"
    >

    <corners
        ohos:radius="100"/>

    <!--    内部透明 -->
    <solid
        ohos:color="#0AFFFFFF"/>

    <!--    边框-->
    <stroke
        ohos:width="2vp"
        ohos:color="#FFFFFF"
        />

</shape>

background_button.xml

<?xml version="1.0" encoding="utf-8"?>

<shape
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:shape="rectangle"
    >

    <corners
        ohos:radius="100"/>

    <solid
        ohos:color="#007DFF"/>

</shape>
  1. 页面代码:
package com.example.myapplication.slice;

import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class LoginAbilitySlice extends AbilitySlice {

    static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00201, "LoginAbilitySlice");

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_login);

        Button button = (Button) findComponentById(ResourceTable.Id_loginButton);

        if (null != button) {
            button.setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    HiLog.info(label, "登录中...");

                    ToastDialog toastDialog = new ToastDialog(getContext());
                    toastDialog .setAlignment(LayoutAlignment.CENTER);
                    toastDialog.setText("登录中...").setDuration(1000).show();
                }
            });
        }
    }
}

4.效果图
在这里插入图片描述

  • 4
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值