:core:uiモジュールにcomponentsディレクトリ(パッケージ)を作成します。
:core:uiモジュールに依存モジュールを追記します。
:
dependencies {
:
implementation(project(":core:resources"))
:
debugImplementation(libs.androidx.ui.tooling)
:
}
追記後、『Sync Now』で内容をプロジェクトに反映させます。
componentsディレクトリ(パッケージ)の直下に、子画面の上部に表示するアプリケーションのタイトルボックスAppTitleBox.ktを作成します。
package jp.co.progress_llc.portal.core.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.Alignment
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import jp.co.progress_llc.portal.core.resources.R
import jp.co.progress_llc.portal.core.ui.theme.AppTheme
@Composable
fun AppTitleBox(
modifier: Modifier = Modifier
) {
Box(
modifier = modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.primaryContainer)
.padding(horizontal = 12.dp, vertical = 8.dp),
contentAlignment = Alignment.Center
) {
Text(
text = stringResource(R.string.company_name) + stringResource(R.string.app_name),
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onPrimaryContainer
)
}
}
@Preview(showBackground = true)
@Composable
fun AppTitleBoxPreview() {
AppTheme {
AppTitleBox()
}
}