HarmonyOS | 使用鸿蒙实现登录页面【XML】

效果展示

在这里插入图片描述

代码展示

在 ability_main.xml 文件中编写如下代码完成页面搭建

<?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">

    <Text
        ohos:height="50vp"
        ohos:width="319vp"
        ohos:text="请输入账号"
        ohos:text_size="17fp"
        ohos:text_color="#999999"
        ohos:top_margin="122vp"
        ohos:left_margin="20vp"
        ohos:right_margin="20vp"
        ohos:text_alignment="center"
        ohos:background_element="#fff"/>

    <Text
        ohos:height="50vp"
        ohos:width="319vp"
        ohos:text="请输入密码"
        ohos:text_size="17fp"
        ohos:text_color="#999999"
        ohos:top_margin="10vp"
        ohos:left_margin="20vp"
        ohos:right_margin="20vp"
        ohos:text_alignment="center"
        ohos:background_element="#fff"/>

    <Text
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:text="忘记密码?"
        ohos:text_size="16fp"
        ohos:text_color="#979797"
        ohos:top_margin="12vp"
        ohos:right_margin="20vp"
        ohos:layout_alignment="right"/>

    <Button
        ohos:height="46vp"
        ohos:width="320vp"
        ohos:text="登录"
        ohos:text_size="25fp"
        ohos:text_color="#fefefe"
        ohos:background_element="$graphic:background_radioBorder"
        ohos:text_alignment="center"
        ohos:layout_alignment="center"
        ohos:top_margin="77vp"/>

    <Button
        ohos:height="46vp"
        ohos:width="320vp"
        ohos:text="注册"
        ohos:text_size="25fp"
        ohos:text_color="#fefefe"
        ohos:background_element="$graphic:background_radioBorder"
        ohos:text_alignment="center"
        ohos:layout_alignment="center"
        ohos:top_margin="13vp"/>

</DirectionalLayout>

在 resource – base – graphic 文件夹中新建一个 background_radioBorder.xml 文件,并编写如下代码,修改按钮的的样式。
·
引用方式:ohos:background_element="$graphic:background_radioBorder"

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:shape="rectangle">
    <corners
        ohos:radius="10vp"/>
    <solid
        ohos:color="#21a8fd"/>
</shape>

怎么样?是不是很简单?赶快动手试一下吧!

如果有兴趣的话,你还可以尝试着做一下【注册页面】

上文中用于输入账号密码的文本输入框使用 Text 组件代替,你也可以尝试使用 文本输入框组件 【TextField】 完成

  • 11
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QX_Java_Learner

祝老板生意兴隆,财源广进!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值