当前位置:   article > 正文

Android studio - UI 界面设计(仿问卷星登陆注册界面)_android studio 界面设计

android studio 界面设计

1 先上效果图:

请添加图片描述

2 准备工作 建如下活动文件以及素材文件

在这里插入图片描述

3 代码实现

3.1 修改themes.xml、 themes.xml(night)文件 使自定义按钮组件起效果

在这里插入图片描述

	在框出区域加	.Bridge 两个 xml 文件都要加
  • 1

在这里插入图片描述

	**自定义按钮的应用**
  • 1

在这里插入图片描述

代码实现

btn_login.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#00000000"/>
    <!--颜色 透明-->
    <corners android:radius="30dp"/>
    <!--标准圆角-->
</shape>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

button_lg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <!--  灰色 圆角按钮  -->
    <solid android:color="#CCCCCC"/>
    <corners android:radius="120dip"/>

</shape>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

button_res.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <!--  蓝色圆角按钮  -->
    <corners android:radius="120dip"/>
    <solid android:color="#0099FF"/>

</shape>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
3.2 实现布局
LinearLayout(线性布局) 和 RelativeLayout(相对布局)
  • 1
3.2.1 登陆界面 activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LoginActivity"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="-10dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="180dp"
            android:src="@drawable/bj" />
    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="-20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_gravity="bottom"
        android:showDividers="middle">

        <Button
            android:id="@+id/bt_lg"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_login"
            android:layout_weight="1"
            android:text="登陆"
            android:textSize="30dp"
            android:textColor="#03A9F4"
            android:textStyle="bold"
            android:letterSpacing="0.5">
        </Button>


        <Button
            android:id="@+id/bt_reg"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_login"
            android:layout_weight="1"
            style="?android:attr/borderlessButtonStyle"
            android:text="注册"
            android:textSize="30dp"
            android:textColor="#999999"
            android:textStyle="bold"
            android:letterSpacing="0.5"/>
    </LinearLayout>

    <View
        android:layout_gravity="center"
        android:layout_width="350dp"
        android:layout_height="1dp"
        android:background="#000000" />

    <LinearLayout
        android:layout_marginTop="15dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <EditText
            android:id="@+id/et_phone"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:drawableLeft="@drawable/pn"
            android:inputType="phone"
            android:drawablePadding="10dp"
            android:hint="请输入手机号"
            android:letterSpacing="0.15"
            android:textSize="20sp" />

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <EditText
            android:id="@+id/et_pwd"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:drawableLeft="@drawable/pwd"
            android:drawablePadding="10dp"
            android:hint="请输入密码"
            android:inputType="numberPassword"
            android:letterSpacing="0.15"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/forget_pwd"
            android:layout_width="130dp"
            android:layout_height="80dp"
            android:layout_alignParentEnd="true"
            android:gravity="center_vertical"
            android:hint="忘记密码?"
            android:textColorHint="#3399FF"
            android:textSize="25sp"
            android:textStyle="bold" />

    </RelativeLayout>

    <LinearLayout
        android:layout_marginTop="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp">

        <Button
            android:id="@+id/bt_lg1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/button_lg"
            android:text="登 陆"
            android:textColor="#999999"
            android:textSize="25sp"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="45dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">

        <TextView
            android:gravity="center_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="95dp"
            android:drawableTop="@drawable/wx"
            android:drawablePadding="10dp"
            android:text="微信登陆"
            android:textColor="#C0C0C0"
            android:textStyle="bold"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"/>
        <TextView
            android:gravity="center_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="95dp"
            android:drawableTop="@drawable/qq"
            android:drawablePadding="10dp"
            android:text="QQ登陆"
            android:textColor="#C0C0C0"
            android:textStyle="bold"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"/>
        <TextView
            android:gravity="center_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="95dp"
            android:drawableTop="@drawable/phone"
            android:drawablePadding="10dp"
            android:text="短信登陆"
            android:textColor="#C0C0C0"
            android:textStyle="bold"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"/>

    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="30dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <RadioButton
            android:id="@+id/rb1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="我同意问卷星"
            android:textColor="#CCCCCC"
            android:textStyle="bold"
            tools:ignore="TouchTargetSizeCheck" />
        <TextView
            android:id="@+id/t1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="《用户服务协议》"
            android:textColor="#3399FF"
            android:textStyle="bold"/>
        <TextView
            android:id="@+id/t2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="和"
            android:textColor="#CCCCCC"
            android:textStyle="bold"/>
        <TextView
            android:id="@+id/t3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="《隐私条款》"
            android:textColor="#3399FF"
            android:textStyle="bold"/>
    </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
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
	登陆效果图如下
  • 1

请添加图片描述

3.2.2 注册界面 activity_register.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".RegisterActivity"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="-10dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="180dp"
            android:src="@drawable/bj" />
    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="-20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_gravity="bottom"
        android:showDividers="middle">

        <Button
            android:id="@+id/bt_lg"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_login"
            android:layout_weight="1"
            android:text="登陆"
            android:textSize="30dp"
            android:textColor="#999999"
            android:textStyle="bold"
            android:letterSpacing="0.5">
        </Button>


        <Button
            android:id="@+id/bt_reg"
            android:layout_width="200dp"
            android:layout_height="wrap_content"
            android:background="@drawable/btn_login"
            android:layout_weight="1"
            style="?android:attr/borderlessButtonStyle"
            android:text="注册"
            android:textSize="30dp"
            android:textColor="#03A9F4"
            android:textStyle="bold"
            android:letterSpacing="0.5"/>
    </LinearLayout>

    <View
        android:layout_gravity="center"
        android:layout_width="350dp"
        android:layout_height="1dp"
        android:background="#000000" />

    <LinearLayout
        android:layout_marginTop="15dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <EditText
            android:id="@+id/et_phone"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:drawableLeft="@drawable/pn"
            android:inputType="phone"
            android:drawablePadding="10dp"
            android:hint="请输入手机号"
            android:textColorHint="#808080"
            android:textStyle="bold"
            android:letterSpacing="0.15"
            android:textSize="20sp" />

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <EditText
            android:id="@+id/et_dx"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:drawableLeft="@drawable/dx"
            android:inputType="phone"
            android:drawablePadding="10dp"
            android:hint="短信码验证"
            android:letterSpacing="0.15"
            android:textColorHint="#808080"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/forget_pwd"
            android:layout_width="130dp"
            android:layout_height="80dp"
            android:layout_alignParentEnd="true"
            android:gravity="center_vertical"
            android:hint="获取验证码"
            android:textColorHint="#3399FF"
            android:textSize="25sp"
            android:textStyle="bold" />

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <EditText
            android:id="@+id/et_pwd"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:drawableLeft="@drawable/pwd"
            android:inputType="numberPassword"
            android:drawablePadding="10dp"
            android:hint="8-20位密码"
            android:textColorHint="#808080"
            android:textStyle="bold"
            android:letterSpacing="0.15"
            android:textSize="20sp" />

    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp">

        <Button
            android:id="@+id/bt_lg1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/button_res"
            android:text="注 册"
            android:textColor="#ffffff"
            android:textSize="25sp"
            android:textStyle="bold" />

    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="100dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal">

        <RadioButton
            android:id="@+id/rb1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="我同意问卷星"
            android:textColor="#696969"
            android:textStyle="bold"
            tools:ignore="TouchTargetSizeCheck" />
        <TextView
            android:id="@+id/t1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="《用户服务协议》"
            android:textColor="#3399FF"
            android:textStyle="bold"/>
        <TextView
            android:id="@+id/t2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="和"
            android:textColor="#696969"
            android:textStyle="bold"/>
        <TextView
            android:id="@+id/t3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="《隐私条款》"
            android:textColor="#3399FF"
            android:textStyle="bold"/>
    </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
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
	注册界面效果如下:
  • 1

请添加图片描述

4 按钮实现页面跳转

4.1 LoginActivity.java
package com.example.你的项目名;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        Button button1 = findViewById(R.id.bt_lg);
        button1.setOnClickListener(this);

        Button button2 = findViewById(R.id.bt_reg);
        button2.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bt_lg:

                final Intent intent1 = new Intent(LoginActivity.this, LoginActivity.class);
                startActivity(intent1);
                break;

            case R.id.bt_reg:
                final Intent intent2 = new Intent(LoginActivity.this, RegisterActivity.class);
                //启动活动(参数)
                startActivity(intent2);
                break;
        }
    }
}
  • 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
4.2 RegisterActivity.java
package com.example.你的项目名;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        Button button1 = findViewById(R.id.bt_lg);
        button1.setOnClickListener(this);

        Button button2 = findViewById(R.id.bt_reg);
        button2.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bt_lg:

                final Intent intent1 = new Intent(RegisterActivity.this, LoginActivity.class);
                startActivity(intent1);
                break;

            case R.id.bt_reg:
                final Intent intent2 = new Intent(RegisterActivity.this, RegisterActivity.class);
                //启动活动(参数)
                startActivity(intent2);
                break;
        }
    }
}
  • 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
最后,在 AndroidManifest.xml	
				中设置启动页保证两个页面都能实现跳转。
  • 1
  • 2

在这里插入图片描述
最后,如有问题或指正的地方,请在下方评论,一起讨论学习。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/271909
推荐阅读
相关标签