5
5
.
.
2
2
.
.
2
2
.
.
w
w
i
i
d
d
t
t
h
h
I
I
n
n
f
f
o
o
.width modifier defines width of the View.
Syntax
.width()
E
E
x
x
a
a
m
m
p
p
l
l
e
e
MainActivity.kt
package com.example.testcompose
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.ui.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.foundation.layout.Box
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Box(Modifier.fillMaxSize()) {
Text(
text = "Text",
textAlign = TextAlign.Center,
modifier = Modifier
.align(Alignment.Center)
.border (2.dp, Color.Red)
.width (300.dp)
.height (100.dp)
)
}
}
}
}
Output