Button ve onClick
Kullanıcı dokunduğunda kod çalıştırın.
Button ve onClick, CoddyKit'te ücretsiz bir Jetpack Compose Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Jetpack Compose Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Tap, Then React
A button is your app's simplest conversation: the user taps, your code runs. In Compose you express this with the Button composable. 👆
The Button Composable
A Button needs two things: an onClick action and some content to show, usually a Text label inside its trailing lambda.
Button(onClick = { /* do work */ }) {
Text("Tap me")
}onClick Runs on Tap
The onClick lambda runs once each time the button is pressed. Put any plain Kotlin code you want there, like updating a value.
Button(onClick = { count = count + 1 }) {
Text("Add one")
}Content Is a Lambda
Everything between the button's braces is its content. You are not limited to text; any composable can live inside that slot.
Button(onClick = { send() }) {
Text("Send now")
}Wire Up Real State
onClick really shines with state: change a value there and the UI redraws to match the new value automatically.
var liked by remember { mutableStateOf(false) }
Button(onClick = { liked = !liked }) {
Text(if (liked) "Liked" else "Like")
}Call a Function
For tidy code, point onClick at a named function instead of inlining logic. Your UI stays readable and the logic stays testable.
Button(onClick = ::saveProfile) {
Text("Save")
}Buttons Look Filled by Default
A plain Button renders as a filled, high-emphasis button: solid background, contrasting label. It signals the main action on a screen.
One Primary Action
Reserve the filled Button for the single most important action, like Submit or Continue. Too many filled buttons compete for attention.
Empty onClick Does Nothing
An empty onClick lambda compiles fine and the button still ripples, but nothing happens. Always wire it to real behavior. 🤔
Button(onClick = { }) {
Text("Does nothing yet")
}Pass a Modifier
Like most composables, Button accepts a modifier so you can size, pad, or space it within its parent layout.
Button(
onClick = { go() },
modifier = Modifier.fillMaxWidth()
) { Text("Continue") }Tap to Confirm
Think of onClick as the moment of commitment: the user has decided. Use it to save, navigate, or trigger the work they asked for.
Quick Check
You wrote a Button but tapping it does nothing.
Recap: Tap Into Action
You met the Button composable: an onClick lambda for behavior plus a content lambda for its label. Tap, run code, update state. 🎉
Sıkça Sorulan Sorular
“Button ve onClick” dersi ücretsiz mi?
Evet — “Button ve onClick” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Jetpack Compose Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.
“Button ve onClick” dersinde ne öğreneceğim?
Kullanıcı dokunduğunda kod çalıştırın. Jetpack Compose Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Jetpack Compose Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Jetpack Compose Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.
“Button ve onClick” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Jetpack Compose Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Jetpack Compose Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Button ve onClick
- Text, Outlined ve Icon Düğmeleri
- Etkin, Devre Dışı ve Yükleniyor Durumları
- Her Composable'da clickable