-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
69 lines (57 loc) · 2.52 KB
/
MainActivity.java
File metadata and controls
69 lines (57 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.example.pre_workhelloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = ((TextView) findViewById(R.id.text ));
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((TextView) findViewById(R.id.text)).setTextColor(getResources().getColor(R.color.coral));
}
});
// change background color
findViewById(R.id.changeBackgroundButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
findViewById(R.id.parent).setBackgroundColor(getResources().getColor(R.color.light_blue));
}
});
// can change text to string
findViewById(R.id.changeTextButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((TextView)findViewById(R.id.text)).setText("Android is Awesome!");
}
});
// reset all
findViewById(R.id.parent).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.setText("Hello from Ferduse!");
textView.setTextColor(getResources().getColor(R.color.black));
findViewById(R.id.parent).setBackgroundColor(getResources().getColor(R.color.blue));
}
});
//update label
findViewById(R.id.changeCustomTextButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// change text view to edit text view
String userEnteredText = ((EditText) findViewById(R.id.editText)).getText().toString();
// if field is empty, update label
if (userEnteredText.isEmpty()) {
textView.setText("Enter your own text!");
} else {
textView.setText(userEnteredText);
}
}
});
}
}