TopAppBarとアクションアイコン
アクション付きのタイトルバーを追加します。
「TopAppBarとアクションアイコン」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
The Title Bar
The strip across the top with your screen name and actions is the TopAppBar. It gives users a stable anchor that says where they are. 🧭
A Minimal TopAppBar
At its simplest, a TopAppBar just needs a title. Drop it into the Scaffold topBar slot and you have a real Material header.
TopAppBar(
title = { Text("Inbox") }
)Title Is a Composable
Notice the title takes a Composable lambda, not a String. That means you can put any content there, though usually a single Text fits best.
The navigationIcon Slot
The leading navigationIcon slot holds your back or menu button. Wrap an Icon in an IconButton so it is tappable and sized correctly.
navigationIcon = {
IconButton(onClick = { }) {
Icon(Icons.Default.Menu, "Menu")
}
}The actions Slot
Trailing buttons go in the actions slot. It is a RowScope, so each IconButton you add lines up neatly on the right edge.
actions = {
IconButton(onClick = { }) {
Icon(Icons.Default.Search, "Search")
}
}Always Pass contentDescription
Every Icon in a bar needs a contentDescription. Screen readers announce it, so a Search icon should say Search, not stay silent.
Bar Variants
Material 3 offers CenterAlignedTopAppBar, MediumTopAppBar, and LargeTopAppBar. They differ only in title size and alignment, so pick by feel.
Coloring the Bar
Use TopAppBarDefaults.topAppBarColors to recolor the container and title. Lean on theme colors so the bar stays consistent in light and dark.
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primary
)Collapsing Bars
Pass a scrollBehavior and connect it to your content's nested scroll to make large bars shrink as the user scrolls down.
Do Not Overcrowd
Keep actions to two or three icons. Move the rest behind an overflow menu so the bar stays readable on small phones.
Wire It to Scaffold
The bar lives in Scaffold's topBar slot, so the content area shrinks automatically and your screen body never hides behind it.
Scaffold(topBar = { TopAppBar(title = { Text("Home") }) }) { p -> }Quick Check
You add a search IconButton to a TopAppBar. Where does it belong?
Recap
A TopAppBar holds a title, a leading navigationIcon, and trailing actions. Describe every icon, keep it tidy, and place it in the topBar slot. ✨
よくある質問
「TopAppBarとアクションアイコン」レッスンは無料ですか?
はい。「TopAppBarとアクションアイコン」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。
「TopAppBarとアクションアイコン」で何を学びますか?
アクション付きのタイトルバーを追加します。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Jetpack Compose Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「TopAppBarとアクションアイコン」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このJetpack Compose Academyレッスンでコードを書いて実行できますか?
はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Scaffold:画面の骨組み
- TopAppBarとアクションアイコン
- 下部バーとフローティングアクションボタン
- SnackbarとSnackbarHostState