牙叔教程 簡單易懂javascript
9.0.4java
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);
複製代碼
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>
);
複製代碼
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;
}
複製代碼
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