使用dialog提示信息

package com.example.androidtest2;

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 implements View.OnClickListener {
    private EditText editText;
    private ImageView imageView;
    private ProgressBar progressBar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.Button);
        editText =(EditText) findViewById(R.id.edit_text);
        imageView = (ImageView) findViewById(R.id.image_view);
        progressBar = (ProgressBar) findViewById(R.id.progress_bar);
        button.setOnClickListener(this);
    }
    public  void onClick(View v){
        switch (v.getId()){
            case R.id.Button:
                int progress = progressBar.getProgress();
                progress = progress+10;
                AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
                dialog.setTitle("有个超级重要的信息");
                dialog.setMessage("大家手里还有硬币吗?");
                dialog.setCancelable(false);
                dialog.setPositiveButton("都给你", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
            });
                dialog.show();
                    //这里写逻辑
                break;
            default:
                break;
        }

    }
}

你可能感兴趣的:(andro,studio,学习笔记,android-studio,android,小程序,android,studio)