3分钟
2.5 实施步骤
实施步骤
步骤1:新建一个Module,命名为Ex2_5。
步骤2:打开AndroidManifest.xml文件, 寻找android:theme,将其值改为"@style/Theme.AppCompat.Light.NoActionBar",即设置本应用的主题为无标题栏样式。
步骤3:添加图片资源。将bus.png、header24.png、lock24.png复制到/res/drawable目录下。
步骤4:修改activity_main.xml文件,清单如下。
表2-5-1 Ex2_5 activity_main.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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20px"
android:paddingRight="20px"
android:orientation="vertical"
android:background="#DFEBEB"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/bus" />
<!--drawableLeft属性是设置一个左侧的图标,该图标在Android5.0上需要预先处理好大小,
本案例中width=24px,height=24px。
-->
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/header24"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:textAlignment="center"
android:hint="请输入您的账号"
android:ems="10"
android:inputType="textPersonName"
/>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/lock24"
android:ems="10"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:hint="请输入您的密码"
android:inputType="textPassword"
android:textAlignment="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#23AD71"
android:layout_weight="1"
android:text="记住密码" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#23AD71"
android:layout_gravity="center"
android:text="修改密码" />
</LinearLayout>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#23AD71"
android:textColor="#ffffff"
android:textSize="22dp"
android:layout_marginTop="20px"
android:text="登 陆"
/>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#23AD71"
android:textColor="#ffffff"
android:textSize="22dp"
android:layout_marginTop="20px"
android:text="注 册" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#23AD71"
android:textColor="#ffffff"
android:textSize="22dp"
android:layout_marginTop="20px"
android:text="注 销" />
</LinearLayout>
学员评价