android添加输入框和按钮
时间: 2023-09-26 17:09:21 浏览: 48
要在Android中添加输入框和按钮,可以按照以下步骤进行:
1. 在XML布局文件中添加EditText控件和Button控件,例如:
```
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入内容"
android:inputType="text"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="确定"/>
```
2. 在Java代码中获取EditText和Button控件的引用,例如:
```
EditText editText = findViewById(R.id.editText);
Button button = findViewById(R.id.button);
```
3. 给Button控件设置点击事件,例如:
```
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String inputText = editText.getText().toString();
// TODO: 处理输入内容
}
});
```
在点击Button控件时,可以获取EditText控件中的输入内容,并进行相应的处理。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)