android 登陆输入框的实现

来源:互联网 发布:javascript动画教程 编辑:程序博客网 时间:2024/05/16 04:29

第一次写博客,把自己学到的一点一滴分享出来,方便别人借鉴,也有助于自己的学习。写的不好请见谅,正在进步中。

先看一下效果图


mainActivity中不需要增加什么代码,主要看main.xml中

<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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="com.example.shurukuang.MainActivity">    <LinearLayout        android:layout_marginTop="100dp"        android:layout_centerHorizontal="true"        android:layout_width="300dp"        android:layout_height="wrap_content"        android:background="@drawable/shape_tousu"        android:orientation="vertical">        <LinearLayout            android:layout_width="match_parent"            android:layout_height="40dp"            android:gravity="center"            android:orientation="horizontal">            <TextView                android:id="@+id/login_yisheng_tv"                android:clickable="true"                android:layout_weight="1"                android:textSize="18dp"                android:paddingLeft="18dp"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:hint="用户名"/>        </LinearLayout>        <View            android:layout_width="match_parent"            android:layout_height="1dp"            android:background="#cbcece" />        <LinearLayout            android:layout_width="match_parent"            android:layout_height="40dp"            android:gravity="center_vertical">            <EditText                android:id="@+id/login_shoujihaoma_ed"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:paddingLeft="18dp"                android:textSize="15dp"                android:background="@null"                android:hint="密码"/>        </LinearLayout>        <View            android:layout_width="match_parent"            android:layout_height="1dp"            android:background="#cbcece" />        <LinearLayout            android:layout_width="match_parent"            android:gravity="center_vertical"            android:layout_height="40dp">            <EditText                android:id="@+id/login_mima_ed"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:paddingLeft="18dp"                android:textSize="15dp"                android:background="@null"                android:inputType="textPassword"                android:hint="手机号"/>        </LinearLayout>    </LinearLayout></RelativeLayout>
主要是在大的LinearLayout中设置一个drawable/shape_tousu   然后用view分成一格一格的。

shape_tousu.xml放在drawable中

<?xml version="1.0" encoding="utf-8"?><!--矩形的--><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <solid android:color="#ffffff"/>    <padding android:left="1dp"        android:right="1dp"        android:top="1dp"/>    <stroke android:color="#a3a3a3"        android:width="2px"        />    <corners android:radius="6dp"/></shape>
solid:填充的颜色,padding:各方向的间隔,stroke:边框,corners:圆角

这个功能的实现就是这样,如果有什么问题欢迎给我留言。

1 0