帮我设计一个用户注册界面,要求如下:。 (1)将应用的名称、姓名编辑框的输入提示中的 “张三”,改为自己的拼音姓名;。 《2〉性别的默认选择:男同学为 “男”,女同学为 “女”。 〈3)实现“汪册”按键事件监听, T 设置“注册”按钮的监听器,在处理方法中,获取输入的注册信息,并通过 Toast 提示框将注册信息(姓名、性别、爱好)显示出来。例如图 1,点击注册后,提示框里应显示:张三 女 爱好 打兵乓球。
时间: 2024-04-02 19:32:12 浏览: 19
好的,以下是一个简单的用户注册界面的设计,符合您的要求:
XML布局文件:
```xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="应用名称"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入姓名"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性别"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"/>
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="爱好"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册"
android:onClick="register"/>
</LinearLayout>
```
Java代码:
```java
public class MainActivity extends AppCompatActivity {
private EditText nameEditText;
private RadioGroup genderRadioGroup;
private EditText hobbyEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nameEditText = findViewById(R.id.name_edit_text);
genderRadioGroup = findViewById(R.id.gender_radio_group);
hobbyEditText = findViewById(R.id.hobby_edit_text);
}
public void register(View view) {
String name = nameEditText.getText().toString();
String gender = ((RadioButton)findViewById(genderRadioGroup.getCheckedRadioButtonId())).getText().toString();
String hobby = hobbyEditText.getText().toString();
String message = name + " " + gender + " " + "爱好 " + hobby;
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
}
```
在这个界面中,应用名称使用 TextView 显示,姓名、性别、爱好使用 EditText 接收用户输入。性别使用 RadioGroup 和两个 RadioButton 实现默认选择。注册按钮使用 onClick 属性绑定 register 方法,该方法从 EditText 和 RadioButton 中获取用户输入信息,使用 Toast 显示注册信息。
注意:在 AndroidManifest.xml 文件中添加权限 `<uses-permission android:name="android.permission.INTERNET"/>`,以允许应用使用 Toast。