iT邦幫忙

0

每日一篇學習筆記 直到我做完專題 :( [Day17]

  • 分享至 

  • xImage
  •  

今天學習系統的提醒對話框

利用系統對話框來選擇顯示甚麼訊息

public class AlertDialogActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tv_alert;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_alert_dialog);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        findViewById(R.id.btn_alert).setOnClickListener(this);
        tv_alert = findViewById(R.id.tv_alert);
    }

    @Override
    public void onClick(View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("親愛的用戶");
        builder.setMessage("你真的要卸載嗎?");
        builder.setPositiveButton("確定卸載", (dialogInterface, i) -> {
            tv_alert.setText("謝謝您的配伴,後會有期");
        });
        builder.setNegativeButton("取消卸載", (dialogInterface, i) -> {
            tv_alert.setText("我會持續提升自己的");
        });

        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }
}

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言