url一键转md
html转md
一键转换保存为 MD
- H**
- **
**一、新建一个空的LoginActivity
**二、在activity.login.xml中进行布局设计
**(一)那么如何打开呢这个.xml文件呢?
**新建activity后里面会有初始代码,按住Ctrl键点击activity.login就可以进入xml文件了。
**(二)如何进行登录界面的布局设计呢?
**首先把这个xml改成线性布局,把这个改成LinearLayout。
**然后进行布局界面设计
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@color/white"
android:orientation="vertical"
tools:context=".LoginActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/purple_200"
android:textSize="40dp"
android:background="@color/white"
android:gravity="center"
android:text="登录系统"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:textSize="25sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:text="用户名"/>
</LinearLayout>
<EditText
android:id="@+id/login_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
>
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="密码"
android:textColor="@color/black"
android:textSize="25sp" />
</LinearLayout>
<EditText
android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword">
</EditText>
<LinearLayout
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/login_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="登录">
</Button>
<Button
android:id="@+id/reg_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="注册">
</Button>
</LinearLayout>
</LinearLayout>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89\
**布局界面展示
**三、点击进行页面进行跳转
**(一)新建一个注册activity与主页面activity
**首先呢,咱们得先有个跳转后的主页面和注册页面,这里为了方便演示,就简单整个注册页面和主页面吧!狗头保命
**(二)分别在这俩布局里面随便写点标识的东西
**(三)在LoginActivity中用Intent对其实现跳转
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button button = findViewById(R.id.login_btn);
Button button1 = findViewById(R.id.reg_btn);
EditText e_username = findViewById(R.id.login_name);
EditText e_password = findViewById(R.id.login_password);
String username = e_username.getText().toString();
String password = e_password.getText().toString();
//点击登录按钮,实现跳转
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(LoginActivity.this,username,Toast.LENGTH_SHORT);
Toast.makeText(LoginActivity.this,password,Toast.LENGTH_SHORT);
Intent intent = new Intent(LoginActivity.this,HomeActivity.class);
startActivity(intent);
}
});
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this,RestActivity.class);
startActivity(intent);
}
});
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46\
**狗头三连 ~~~~~~~~~~~~~~~~~~~
本文转自 blog.csdn.net/weixin_4747…,如有侵权,请联系删除。
**