用Android studio 写母亲节的软件
时间: 2024-05-13 15:19:19 浏览: 15
好的,我们可以写一个简单的母亲节祝福卡应用程序。以下是一个基本的示例:
1. 首先,在 Android Studio 中创建一个新项目,选择空活动。
2. 在 MainActivity 中添加以下代码:
```
public class MainActivity extends AppCompatActivity {
private Button btnSend;
private EditText edtMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 初始化控件
btnSend = findViewById(R.id.btn_send);
edtMessage = findViewById(R.id.edt_message);
// 添加按钮点击事件
btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String message = edtMessage.getText().toString();
// 弹出祝福信息
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
}
});
}
}
```
3. 在布局文件 activity_main.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:padding="16dp">
<EditText
android:id="@+id/edt_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入祝福语"
android:maxLines="5"
android:padding="8dp" />
<Button
android:id="@+id/btn_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发送" />
</LinearLayout>
```
4. 运行应用程序,输入祝福语并点击发送按钮,即可弹出 Toast 弹窗显示祝福语。
这只是一个简单的示例,你可以根据自己的需要添加更多的功能和设计。希望可以帮助到你!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)