引言
又是一年的毕业季到了,只不过这次稍有些不同的是:以往是我看别人学长学姐们忙碌着毕业,这次是我忙碌着毕业。整个大学过来,不能说自己已经成为了计算机专业的专业人士,只能说自己还是个半吊子水平的样子。好了,废话说了这么多,今天主要是想跟大家分享一下自己用于毕设的登录界面。
1.效果图
2.实现代码
1.xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shape_gradient"
android:orientation="vertical"
tools:context="com.example.iot.LoginActivity">
<!-- android:background="@drawable/shape_gradient"--><!---->
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/imageView1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:scaleType="fitCenter"
android:src="@drawable/user"
app:riv_border_color="#F0FFFF"
app:riv_border_width="5dip"
app:riv_corner_radius="30dip"
app:riv_mutate_background="true"
app:riv_oval="true"
app:riv_tile_mode="clamp" />
<com.github.florent37.materialtextfield.MaterialTextField
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
app:mtf_backgroundColor="#FFFAFA"
app:mtf_image="@drawable/user"
app:mtf_labelColor="#666">
<EditText
android:id="@+id/Edt_Usernames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Usernames"
android:textColor="#333"
android:textSize="15sp" />
</com.github.florent37.materialtextfield.MaterialTextField>
<com.github.florent37.materialtextfield.MaterialTextField
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:mtf_backgroundColor="#FFFAFA"
app:mtf_image="@drawable/password"
app:mtf_labelColor="#666">
<EditText
android:id="@+id/Edt_Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:password="true"
android:textColor="#333"
android:textSize="15sp" />
</com.github.florent37.materialtextfield.MaterialTextField>
<mehdi.sakout.fancybuttons.FancyButton
android:id="@+id/btn_login"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:paddingBottom="10dp"
fancy:fb_borderColor="#FFFFFF"
fancy:fb_borderWidth="1dp"
fancy:fb_defaultColor="#B0C4DE"
fancy:fb_focusColor="#9bd823"
fancy:fb_radius="30dp"
fancy:fb_text="登录"
fancy:fb_textColor="#FFFFFF"
fancy:fb_textGravity="center" />
<TextView
android:id="@+id/Tv_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:clickable="true"
android:gravity="center_horizontal"
android:text="还没账号?点击立即注册"
android:textColor="#7FFFAA"
android:textSize="15sp"></TextView>
</LinearLayout>
2.java代码
package com.example.iot;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.sdsmdg.tastytoast.TastyToast;
import mehdi.sakout.fancybuttons.FancyButton;
public class LoginActivity extends AppCompatActivity {
private FancyButton fancyButton;
private TextView Tv_register;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Theme_AppCompat_Light_NoActionBar);
setContentView(R.layout.activity_login);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
init();
}
private void init() {
fancyButton = this.findViewById(R.id.btn_login);
Tv_register = this.findViewById(R.id.Tv_register);
fancyButton.setEnabled(true);
setonclick();
}
private void setonclick() {
fancyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
TastyToast.makeText(getApplicationContext(), "Login Success!", TastyToast.LENGTH_SHORT, TastyToast.SUCCESS);
// Toasty.success(LoginActivity.this, "Success!", Toast.LENGTH_SHORT, true).show();
startActivity(intent);
}
});
Tv_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent1 = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent1);
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
总结
想实现这种效果需要大家在androidstudio中导入下方的依赖:
//账号和密码组件
implementation 'com.github.florent37:materialtextfield:1.0.7'
//按钮
implementation 'com.github.medyo:fancybuttons:1.9.1'
//图片效果的控件
implementation 'com.makeramen:roundedimageview:2.3.0'