-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathP16.kt
52 lines (44 loc) · 1.64 KB
/
P16.kt
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
package alpha.beta.dex_three
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.TypedValue
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
class Dynamic : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dynamic)
val ll = findViewById<LinearLayout>(R.id.linerLayout)
val b1 = findViewById<Button>(R.id.b1)
b1.setOnClickListener {
val b2: Button = Button(this)
b2.text = "New Button"
b2.setBackgroundColor(Color.MAGENTA)
b2.setTextColor(Color.WHITE)
b2.layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
).apply {
setMargins(50, 48, 50, 0)
}
val pf: TextView = TextView(this)
pf.text = "New Button Added!"
pf.setTextColor(Color.WHITE)
pf.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f)
pf.layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
).apply {
setMargins(50, 8, 0, 0)
}
b2.setOnClickListener {
Toast.makeText(this, "New Button Added!", Toast.LENGTH_LONG).show()
}
ll.addView(b2)
ll.addView(pf)
}
}
}