teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コード

2020/12/18 03:56

投稿

OSAMURAI
OSAMURAI

スコア10

title CHANGED
File without changes
body CHANGED
@@ -12,4 +12,62 @@
12
12
 
13
13
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14
14
 
15
- どちらもエラーはでないのですが、失敗するコードは何故かボタンをおしたら落ちてしまいます
15
+ どちらもエラーはでないのですが、失敗するコードは何故かボタンをおしたら落ちてしまいます
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+ 全体コード↓
24
+ package com.example.practice;
25
+
26
+ import androidx.appcompat.app.AlertDialog;
27
+ import androidx.appcompat.app.AppCompatActivity;
28
+ import androidx.constraintlayout.widget.ConstraintLayout;
29
+
30
+ import android.content.DialogInterface;
31
+ import android.content.Intent;
32
+ import android.graphics.Color;
33
+ import android.os.Bundle;
34
+ import android.view.KeyEvent;
35
+ import android.view.MotionEvent;
36
+ import android.view.View;
37
+ import android.view.animation.AnimationUtils;
38
+ import android.widget.EditText;
39
+ import android.widget.ImageView;
40
+ import android.widget.RelativeLayout;
41
+ import android.widget.TextView;
42
+ import android.widget.Toast;
43
+
44
+ import java.util.Random;
45
+
46
+ public class MainActivity extends AppCompatActivity {
47
+
48
+
49
+ @Override
50
+ protected void onCreate(Bundle savedInstanceState) {
51
+ super.onCreate(savedInstanceState);
52
+ setContentView(R.layout.activity_main);
53
+
54
+ new AlertDialog.Builder(this)
55
+ .setTitle("背景色")
56
+ .setMessage("背景色を変更しますか")
57
+ .setPositiveButton("Yes",
58
+
59
+ new DialogInterface.OnClickListener() {
60
+ @Override
61
+ public void onClick(DialogInterface dialog, int which) {
62
+ RelativeLayout layout = (RelativeLayout)findViewById(R.id.activity_main);
63
+ layout.setBackgroundColor(Color.BLUE);
64
+
65
+
66
+ }
67
+ }
68
+ )
69
+
70
+ .setNegativeButton("No",null)
71
+ .show();
72
+ }
73
+ }