ユーザ用ツール

サイト用ツール


サイドバー

プログレス合同会社

広告

android:studio:application:feature-depart:app-title-box

02.AppTitleBoxの作成

:core:uiモジュールにcomponentsディレクトリ(パッケージ)を作成します。

依存モジュールを追記

:core:uiモジュールに依存モジュールを追記します。

   :
dependencies {
   :
  implementation(project(":core:resources"))
   :
  debugImplementation(libs.androidx.ui.tooling)
   :
}

4行目
会社名等の共通リソースを参照するため、共通リソースモジュールの依存関係を追記しています。
6行目
画面作成時のプレビューで必要なモジュールの依存関係を追記しています。

追記後、『Sync Now』で内容をプロジェクトに反映させます。

AppTitleBoxの作成

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()
  }
}

18行目
Jetpack Compose関数であることを宣言します。
37行目~43行目
Android Studioで画面のプレビューを表示するための関数を定義しています。
なくても構いません。

android/studio/application/feature-depart/app-title-box.txt · 最終更新: by プログレス合同会社