TextFieldとOutlinedTextField
ユーザーが入力した内容を読み取ります。
「TextFieldとOutlinedTextField」はCoddyKit上の無料Jetpack Compose Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはJetpack Compose Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Jetpack Compose Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why Text Fields Matter
Almost every app asks the user to type something. In Compose, the TextField is your gateway to reading that input. ✏️
The TextField Composable
A TextField shows an editable box. It needs a current value and a callback that fires every time the text changes.
TextField(
value = name,
onValueChange = { name = it }
)State Drives the Value
The field never stores text itself. You hold it in state and feed it back in, so the UI always shows the latest value.
var name by remember { mutableStateOf("") }onValueChange Closes the Loop
Each keystroke calls onValueChange with the new text. You save it to state, Compose redraws, and the field reflects what was typed.
onValueChange = { newText -> name = newText }Meet OutlinedTextField
OutlinedTextField works exactly the same way, but draws a clean border around the input instead of a filled background.
OutlinedTextField(
value = name,
onValueChange = { name = it }
)Filled vs Outlined
The filled TextField has a shaded box and underline. The outlined one is lighter and airier. They behave identically, so pick by style.
Add a Label
A label tells the user what the field is for. It floats above the text once the field is focused or filled.
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Name") }
)Single Line by Default
Set singleLine to true to keep input on one row. The keyboard then shows a Done action instead of a newline.
TextField(
value = name,
onValueChange = { name = it },
singleLine = true
)Read the Value Anywhere
Because the text lives in state, any other Composable can read it. Greet the user the moment they finish typing their name. 👋
Text("Hello, " + name)It Is a Controlled Field
Compose fields are controlled: what you display is whatever you pass as value. Forget to update state and the field appears frozen.
Start Simple, Grow Later
A value plus an onValueChange is all you truly need. Labels, icons, and validation are extras you add on top.
Quick Check
Which parameter receives the user's new text on every keystroke?
Recap
You met TextField and OutlinedTextField: bind a value from state, update it in onValueChange, and add a label. That is text input in Compose. 🎉
よくある質問
「TextFieldとOutlinedTextField」レッスンは無料ですか?
はい。「TextFieldとOutlinedTextField」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Jetpack Compose Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Jetpack Compose Academyコースには全4レッスンが含まれています。
「TextFieldとOutlinedTextField」で何を学びますか?
ユーザーが入力した内容を読み取ります。 ブラウザで直接実行するハンズオンコードでJetpack Compose Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Jetpack Compose Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのJetpack Compose Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「TextFieldとOutlinedTextField」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このJetpack Compose Academyレッスンでコードを書いて実行できますか?
はい。すべてのJetpack Compose Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- TextFieldとOutlinedTextField
- ラベル、プレースホルダー、先頭アイコン
- キーボードの種類とIMEアクション
- インライン検証とエラー状態