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("密码错误");
  }
});


声明

部分内容来自网络

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

相关文章
|
应用服务中间件 nginx
Nginx安装nginx-rtmp-module模块
【2月更文挑战第4天】 nginx中的模块虽然就是类似插件的概念,但是它无法像VsCode那样轻松的安装扩展。 nginx要安装其它模块必须同时拿到nginx源代码和模块源代码,然后手动编译,将模块打到nginx中,最终生成一个名为nginx的可执行文件。
786 6
复选框样式修改(复选框变为圆形)
复选框样式修改(复选框变为圆形)
基于AutoJs过滑块快手极速版脚本
基于AutoJs过滑块快手极速版脚本
390 0
AutoJs4.1.0实战教程---抖音极速版
AutoJs4.1.0实战教程---抖音极速版
379 0
|
Android开发
autojs用ConnectivityManager实现网络监听
autojs用ConnectivityManager实现网络监听
1298 0
|
测试技术 Android开发
autojs动态修改图片src
牙叔教程 简单易懂
1150 0
|
人工智能 前端开发 Java
autojs非常见函数1
牙叔教程 简单易懂
2262 0
|
5月前
|
存储 人工智能 数据库
面向教育场景的大模型 RAG 检索增强解决方案
检索增强生成模型结合了信息检索与生成式人工智能的优点,从而在特定场景下提供更为精准和相关的答案。以人工智能平台 PAI 为例,为您介绍在云上使用一站式白盒化大模型应用开发平台 PAI-LangStudio 构建面向教育场景的大模型 RAG 检索增强解决方案,应用构建更简便,开发环境更直观。此外,PAI 平台同样发布了面向医疗、金融和法律领域的 RAG 解决方案。
|
XML Java Android开发
autojs自定义控件-导航栏
目前自定义控件可以控制的属性: ● 颜色 ● 宽度 ● 图片宽高 ● 绑定viewpager recyclerview的高度是由 文字 + 图片 控制的, 所以就不用设置recyclerview的高度
827 0
|
应用服务中间件 nginx C++
nginx: [emerg] unknown directive “rtmp“ in ./../conf/nginx.conf:16
nginx: [emerg] unknown directive “rtmp“ in ./../conf/nginx.conf:16