button adding

This commit is contained in:
Specoolazius 2021-06-28 16:32:06 +02:00
parent 03f9d010cf
commit 3afa5dd7f0
3 changed files with 31 additions and 6 deletions

View File

@ -45,6 +45,11 @@ class MainActivity : AppCompatActivity() {
) )
setupActionBarWithNavController(navController, appBarConfiguration) setupActionBarWithNavController(navController, appBarConfiguration)
navView.setupWithNavController(navController) navView.setupWithNavController(navController)
addButton( "a", 0xff0000)
addButton( "b", 0xff0000)
addButton( "c", 0xff0000)
addButton( "d", 0xff0000)
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
@ -58,16 +63,19 @@ class MainActivity : AppCompatActivity() {
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
} }
fun addButton(text: String) { fun addButton(userName: String, color: Int) {
val contactScrollField = findViewById<LinearLayout>(R.id.linear_layout)
// = findViewById(R.id.linear_layout) as LinearLayout
val dynamicButton = Button(this) val dynamicButton = Button(this)
dynamicButton.layoutParams = LinearLayout.LayoutParams( /*dynamicButton.layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT LinearLayout.LayoutParams.WRAP_CONTENT
) )*/
dynamicButton.text = "Dynamic Button" dynamicButton.text = userName
dynamicButton.setBackgroundColor(Color.GREEN) dynamicButton.setBackgroundColor(Color.GREEN)
// add Button to LinearLayout
//linearLayout.addView(dynamicButton) contactScrollField.addView(dynamicButton)
} }
} }

View File

@ -17,4 +17,20 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" /> app:navGraph="@navigation/mobile_navigation" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="206dp"
tools:layout_editor_absoluteY="241dp">
<LinearLayout
android:id="@+id/linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -7,4 +7,5 @@
<color name="teal_700">#FF018786</color> <color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color> <color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color> <color name="white">#FFFFFFFF</color>
<color name="green">#00FF0090</color>
</resources> </resources>