autojs简洁的登录界面

简介: 牙叔教程 简单易懂

牙叔教程 简单易懂


效果展示


界面特点


  • 输入框使用TextInputEditText, 上方可显示hint文字, 填写不正确, 右侧下方会提示错误
  • 按钮点击添加动画


autojs版本


9.0.4


你将知道以下知识点


  • 安卓的xml几乎可以拿来就用
  • hint如何始终显示


脚本概况


  • 界面实在太简单了, 没啥好说的


代码讲解


1. 导入类
importClass(android.animation.Animator);
importClass(android.animation.ValueAnimator);
importClass(android.animation.ObjectAnimator);
importClass(android.animation.AnimatorSet);
importClass(android.util.TypedValue);
importClass(android.text.TextUtils);
importClass(android.widget.Toast);


2. 界面xml, 和安卓几乎别无二致
ui.layout(
  <vertical>
    <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#ffffff"
    >
      <card
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="32dp"
        android:layout_marginTop="64dp"
        android:layout_marginRight="32dp"
        android:layout_marginBottom="64dp"
        app:cardCornerRadius="4dp"
        app:cardElevation="8dp"
      >
        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
        >
          <img
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="16dp"
            src="@drawable/ic_account_circle_black_48dp"
          />
          <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginRight="16dp"
            android:hint="用户名"
            app:expandedHintEnabled="true"
            android:textColorHint="#a2c699"
            hintColor="#fff000"
            id="userViewParent"
          >
            <com.google.android.material.textfield.TextInputEditText
              android:id="@+id/edt_user"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textColor="#9966cc"
            />
          </com.google.android.material.textfield.TextInputLayout>
          <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginRight="16dp"
            android:hint="密码"
            app:expandedHintEnabled="true"
            android:textColorHint="#a2c699"
            id="pwdViewParent"
          >
            <com.google.android.material.textfield.TextInputEditText
              android:id="@+id/edt_pwd"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:textColor="#9966cc"
            />
          </com.google.android.material.textfield.TextInputLayout>
          <LinearLayout
            android:layout_width="250dp"
            android:layout_height="55dp"
            android:layout_gravity="center_horizontal"
            android:gravity="center_vertical"
            android:layout_marginTop="48dp"
          >
            <card
              app:cardCornerRadius="8dp"
              android:layout_width="30dp"
              android:layout_height="45dp"
              layout_weight="1"
              margin="19"
              id="buttonParent"
            >
              <Button
                android:id="@+id/btn_login"
                android:text="登录"
                android:textColor="#fcfcfc"
                bg="#9966cc"
                bg="#ff00ff"
              />
            </card>
            <card
              app:cardCornerRadius="8dp"
              android:layout_width="30dp"
              android:layout_height="45dp"
              margin="19"
              layout_weight="1"
              id="buttonParent"
            >
              <Button
                android:id="@+id/btn_reg"
                android:text="注册"
                android:textColor="#fcfcfc"
                bg="#9966cc"
                bg="#ff00ff"
              />
            </card>
          </LinearLayout>
        </LinearLayout>
      </card>
    </RelativeLayout>
  </vertical>
);


3. 创建动画
function createAnimator(view) {
  let animator1 = ObjectAnimator.ofFloat(view, "scaleX", 1, 1.125, 1);
  let animator2 = ObjectAnimator.ofFloat(view, "scaleY", 1, 1.125, 1);
  let animator3 = ObjectAnimator.ofFloat(view, "translationZ", 0, all_2Px("4dp"), 0);
  let set = new AnimatorSet();
  set.playTogether(animator1, animator2, animator3);
  set.setDuration(300);
  return set;
}


4. 给按钮设置点击事件
ui.btn_login.click(function (view) {
  log("点击了登录按钮");
  let set = createAnimator(view);
  set.start();
  let user = ui.edt_user.getText().toString().trim();
  let pwd = ui.edt_pwd.getText().toString().trim();
  if (TextUtils.isEmpty(user) || TextUtils.isEmpty(pwd)) {
    Toast.makeText(context, "用户名或密码不可为空", Toast.LENGTH_SHORT).show();
    return;
  }
  if ("牙叔教程".equals(user) && "123456".equals(pwd)) {
    Toast.makeText(context, "登录成功", Toast.LENGTH_SHORT).show();
  } else if (!"牙叔教程".equals(user)) {
    ui.edt_user.requestFocus();
    ui.edt_user.setError("用户名错误");
  } else if (!"123456".equals(pwd)) {
    ui.edt_pwd.requestFocus();
    ui.edt_pwd.setError("密码错误");
  }
});


声明

部分内容来自网络

本教程仅用于学习, 禁止用于其他用途

相关文章
|
测试技术 Android开发
autojs动态修改图片src
牙叔教程 简单易懂
1295 0
基于AutoJs的94自动运行脚本
基于AutoJs的94自动运行脚本
367 0
|
前端开发 JavaScript UED
前端性能的性能指标之首次内容绘制(FCP)
首次内容绘制(First Content Paint)是前端性能的一个重要指标,因为它是用户体验的一部分,并且对于网页的响应速度和可接受性有很大的影响。
689 0
|
人工智能 JavaScript 定位技术
微信的接口都有哪些?
【10月更文挑战第17天】微信的接口都有哪些?
1245 43
|
8月前
|
数据安全/隐私保护 Python
小红书私信卡片一键生成, 小红书卡片跳转生成器, 小红书跳转卡片免费【python】
就是可以通过代码实现小红书卡片的效果,这个办法非常的稳定,主要问题是因为小红书没有公开的接口
|
存储 人工智能 数据库
面向教育场景的大模型 RAG 检索增强解决方案
检索增强生成模型结合了信息检索与生成式人工智能的优点,从而在特定场景下提供更为精准和相关的答案。以人工智能平台 PAI 为例,为您介绍在云上使用一站式白盒化大模型应用开发平台 PAI-LangStudio 构建面向教育场景的大模型 RAG 检索增强解决方案,应用构建更简便,开发环境更直观。此外,PAI 平台同样发布了面向医疗、金融和法律领域的 RAG 解决方案。
|
Linux 缓存
CENTOS7更换YUM源为163源
访问地址为:http://mirrors.163.com/.help/centos.html 首先备份源: mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 备份之前的源BASE,进入对应目录。
5037 0
|
Python
使用 Python 合并微信与支付宝账单,生成财务报告
这篇博客介绍了如何使用 Python 脚本合并微信与支付宝账单数据,生成自动化财务报告。通过 pandas 库,学习如何清洗、合并和分析账单数据,以及如何生成 Markdown 格式的财务报告。
|
JavaScript 前端开发
autox.js如何打印日志?
autox.js如何打印日志?
|
Web App开发 JavaScript 前端开发
Windows环境下 NVM 介绍、下载安装及使用详解
Windows环境下 NVM 介绍、下载安装及使用详解
2365 0