使用xml编写一个漂亮的登录界面
时间: 2023-01-29 07:59:39 浏览: 110
使用 XML 编写登录界面,首先需要使用布局标签(如 `LinearLayout`、`RelativeLayout` 等)来设定界面的布局方式。
然后,使用视图标签(如 `TextView`、`EditText`、`Button` 等)来添加登录界面所需的元素,如用户名和密码输入框、登录按钮等。
下面是一个示例 XML 代码,它定义了一个登录界面,包含用户名、密码输入框和登录按钮:
```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/username" />
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/password" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword" />
<Button
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login" />
</LinearLayout>
```
该登录界面使用 `LinearLayout` 布局,其中包含了文本标签(`TextView`)和输入框(`EditText`)作为用户名和密码的输入元素,还有一个登录按