質問編集履歴
1
コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,3 +27,119 @@
|
|
27
27
|
|
28
28
|
|
29
29
|
どちらもエラーはでないのですが、失敗するコードは何故かボタンをおしたら落ちてしまいます
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
全体コード↓
|
46
|
+
|
47
|
+
package com.example.practice;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
import androidx.appcompat.app.AlertDialog;
|
52
|
+
|
53
|
+
import androidx.appcompat.app.AppCompatActivity;
|
54
|
+
|
55
|
+
import androidx.constraintlayout.widget.ConstraintLayout;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
import android.content.DialogInterface;
|
60
|
+
|
61
|
+
import android.content.Intent;
|
62
|
+
|
63
|
+
import android.graphics.Color;
|
64
|
+
|
65
|
+
import android.os.Bundle;
|
66
|
+
|
67
|
+
import android.view.KeyEvent;
|
68
|
+
|
69
|
+
import android.view.MotionEvent;
|
70
|
+
|
71
|
+
import android.view.View;
|
72
|
+
|
73
|
+
import android.view.animation.AnimationUtils;
|
74
|
+
|
75
|
+
import android.widget.EditText;
|
76
|
+
|
77
|
+
import android.widget.ImageView;
|
78
|
+
|
79
|
+
import android.widget.RelativeLayout;
|
80
|
+
|
81
|
+
import android.widget.TextView;
|
82
|
+
|
83
|
+
import android.widget.Toast;
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
import java.util.Random;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
public class MainActivity extends AppCompatActivity {
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
@Override
|
98
|
+
|
99
|
+
protected void onCreate(Bundle savedInstanceState) {
|
100
|
+
|
101
|
+
super.onCreate(savedInstanceState);
|
102
|
+
|
103
|
+
setContentView(R.layout.activity_main);
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
new AlertDialog.Builder(this)
|
108
|
+
|
109
|
+
.setTitle("背景色")
|
110
|
+
|
111
|
+
.setMessage("背景色を変更しますか")
|
112
|
+
|
113
|
+
.setPositiveButton("Yes",
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
new DialogInterface.OnClickListener() {
|
118
|
+
|
119
|
+
@Override
|
120
|
+
|
121
|
+
public void onClick(DialogInterface dialog, int which) {
|
122
|
+
|
123
|
+
RelativeLayout layout = (RelativeLayout)findViewById(R.id.activity_main);
|
124
|
+
|
125
|
+
layout.setBackgroundColor(Color.BLUE);
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
)
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
.setNegativeButton("No",null)
|
140
|
+
|
141
|
+
.show();
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|