[code]<?xml version=\"1.0\" encoding=\"utf-8\"?><LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"android:orientation=\"vertical\" android:layout_width=\"match_parent\"android:layout_height=\"match_parent\"><EditTextandroid:id=\"@+id/edit1\"android:hint=\"please input your text\"android:maxLines=\"2\"android:layout_width=\"match_parent\"android:layout_height=\"wrap_content\"/><Buttonandroid:id=\"@+id/deitbutton\"android:text=\"提交\"android:layout_width=\"match_parent\"android:layout_height=\"wrap_content\"/><ImageViewandroid:id=\"@+id/iamgeview\"android:layout_width=\"match_parent\"android:layout_height=\"wrap_content\"android:src=\"@mipmap/ic_launcher\" /><Buttonandroid:id=\"@+id/imagebutton\"android:text=\"切换图片\"android:layout_width=\"match_parent\"android:layout_height=\"wrap_content\"/><ProgressBarandroid:id=\"@+id/progressbar\"android:layout_width=\"match_parent\"android:layout_height=\"wrap_content\"style=\"?android:attr/progressBarStyleHorizontal\"android:max=\"100\"/><Buttonandroid:id=\"@+id/progressbutton\"android:text=\"增加进度条\"android:layout_width=\"match_parent\"android:layout_height=\"wrap_content\"/><Buttonandroid:id=\"@+id/alertbutton\"android:text=\"对话框\"android:layout_width=\"match_parent\"android:layout_height=\"wrap_content\"/></LinearLayout>
xml文件如上
[code]package com.example.myapplication0516;import androidx.appcompat.app.AlertDialog;import androidx.appcompat.app.AppCompatActivity;import android.content.DialogInterface;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.ImageView;import android.widget.ProgressBar;import android.widget.Toast;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button deitbutton = findViewById(R.id.deitbutton);Button imagebutton = findViewById(R.id.imagebutton);Button progressbutton = findViewById(R.id.progressbutton);Button alertbutton = findViewById(R.id.alertbutton);final ImageView imageview = findViewById(R.id.iamgeview);final EditText edittext1 = findViewById(R.id.edit1);final ProgressBar progressbar = findViewById(R.id.progressbar);deitbutton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String text1 = edittext1.getText().toString();Toast.makeText(MainActivity.this,text1,Toast.LENGTH_SHORT).show();}});imagebutton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {imageview.setImageResource(R.drawable.ic_launcher_foreground);}});progressbutton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {int progress = progressbar.getProgress();progress +=10;progressbar.setProgress(progress);}});alertbutton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);dialog.setTitle(\"对话框\");dialog.setMessage(\"这是一个对话框\");dialog.setCancelable(false);dialog.setNegativeButton(\"取消\", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {}});dialog.setPositiveButton(\"确定\", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {}});dialog.show();}});}}
java代码如上
要求如下:
1.设计一个输入框,点击按钮获取输入内容,用通知显示
2.设计一个图片区,点击按钮切换图片
3.设计一个长条形进度条,点击按钮进度增加
4.设计一个对话框