MainActivity.kt
package com.cfsuman.kotlintutorials
import android.app.Activity
import android.os.Bundle
import com.google.android.material.button.MaterialButton
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// get the widgets reference from XML layout
val button7 = findViewById<MaterialButton>(R.id.button7)
val button8 = findViewById<MaterialButton>(R.id.button8)
// programmatically remove padding from material button
button7.minWidth = 0
button7.minimumWidth = 0
button7.minHeight = 0
button7.minimumHeight = 0
button8.minWidth = 0
button8.minimumWidth = 0
button8.minHeight = 0
button8.minimumHeight = 0
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DCDCDC"
android:id="@+id/rootLayout"
android:padding="24dp">
<com.google.android.material.button.MaterialButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Material Button"
app:backgroundTint="#195905"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Material Button"
app:backgroundTint="#880085"
app:layout_constraintBottom_toBottomOf="@+id/button"
app:layout_constraintStart_toEndOf="@+id/button" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Material Button"
app:backgroundTint="#D92121"
app:layout_constraintStart_toStartOf="@+id/button"
app:layout_constraintTop_toBottomOf="@+id/button" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Material Button"
app:backgroundTint="#0A7E8C"
app:layout_constraintBottom_toBottomOf="@+id/button3"
app:layout_constraintStart_toEndOf="@+id/button3" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="Material Button"
app:backgroundTint="#74C365"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button3" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:text="Material Button"
app:backgroundTint="#6050DC"
app:layout_constraintBottom_toBottomOf="@+id/button5"
app:layout_constraintStart_toEndOf="@+id/button5" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Material Button"
app:backgroundTint="#C04000"
app:layout_constraintStart_toStartOf="@+id/button5"
app:layout_constraintTop_toBottomOf="@+id/button5" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Material Button"
app:backgroundTint="#6C2E1F"
app:layout_constraintBottom_toBottomOf="@+id/button7"
app:layout_constraintStart_toEndOf="@+id/button7" />
</androidx.constraintlayout.widget.ConstraintLayout>
build.gradle dependencies
// Material components
implementation 'com.google.android.material:material:1.6.1'