设为首页 加入收藏

TOP

Android项目实战登录&注册(一)
2019-08-30 00:37:45 】 浏览:171
Tags:Android 项目 实战 登录 注册

由于项目中大部分界面都有一个后退键和一个标题栏,为避免代码冗杂以及便于利用,我们可以将后推荐和标题栏单独抽取出来定义一个标题栏布局,在 res/layout 目录下新建一个 Layout resource file ,Root element 选用 RelativeLayout

具体代码如下:

main_title_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/title_bar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@android:color/transparent">

    <TextView
        android:id="@+id/tv_back"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:background="@drawable/go_back_selector" />

    <TextView
        android:id="@+id/tv_main_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textColor="@android:color/white"
        android:textSize="20sp" />

</RelativeLayout>

注册界面
思路
将图片导入 drawable 目录下,在 activity 包下创建 RegisterActivity ,修改 activity_register.xml 为 LinearLayout 布局

具体代码如下:

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:id="@+id/activity_register"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/register_bg"
    android:orientation="vertical"
    tools:context="cn.edu.lt.android.boxueguapp.activity.RegisterActivity">

    <include layout="@layout/main_title_bar"></include><!--引入标题栏-->

    <ImageView
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="25dp"
        android:src="@drawable/default_icon" />

    <EditText
        android:id="@+id/et_username"
        android:layout_width="fill_parent"
        android:layout_height="48dp"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp"
        android:layout_marginTop="35dp"
        android:background="@drawable/register_user_name_bg"
        android:drawableLeft="@drawable/user_name_icon"
        android:drawablePadding="10dp"
        android:gravity="center_vertical"
        android:hint="请输入用户名"
        android:paddingLeft="8dp"
        android:singleLine="true"
        android:textColor="#000000"
        android:textColorHint="#a3a3a3"
        android:textSize="14sp" />

    <EditText
        android:id="@+id/et_pwd"
        android:layout_width="fill_parent"
        android:layout_height="48dp"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp"
        android:background="@drawable/register_psw_bg"
        android:
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 1/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇移动端触摸 下一篇从零学习Fluter(三):Flutter的路..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目