সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
আইকন বোতাম ব্যবহারকারীরা নিতে পারে এমন অ্যাকশন প্রদর্শন করে। আইকন বোতামগুলিকে অবশ্যই একটি স্পষ্ট অর্থ সহ একটি আইকন ব্যবহার করতে হবে এবং সাধারণত সাধারণ বা ঘন ঘন ব্যবহৃত ক্রিয়াগুলিকে উপস্থাপন করতে হবে।
আইকন বোতাম দুই ধরনের আছে:
ডিফল্ট : এই বোতামগুলি মেনু বা অনুসন্ধানের মতো অন্যান্য উপাদানগুলি খুলতে পারে।
টগল করুন : এই বোতামগুলি বাইনারি ক্রিয়াগুলিকে উপস্থাপন করতে পারে যা চালু বা বন্ধ করা যেতে পারে, যেমন "প্রিয়" বা "বুকমার্ক"।
চিত্র 1. আইকন বোতাম, যার মধ্যে কিছু পূর্ণ (নির্বাচন নির্দেশ করে) এবং রূপরেখা।
onClick : একটি ল্যাম্বডা ফাংশন যা ব্যবহারকারী যখন আইকন বোতামে ট্যাপ করে তখন কার্যকর করে।
enabled : একটি বুলিয়ান যা বোতামের সক্রিয় অবস্থা নিয়ন্ত্রণ করে। false হলে, বোতামটি ব্যবহারকারীর ইনপুটে সাড়া দেয় না।
content : বোতামের ভিতরে কম্পোজযোগ্য বিষয়বস্তু, সাধারণত একটি Icon ।
মৌলিক উদাহরণ: টগল আইকন বোতাম
এই উদাহরণটি আপনাকে দেখায় কিভাবে একটি টগল আইকন বোতাম বাস্তবায়ন করতে হয়। একটি টগল আইকন বোতাম নির্বাচিত বা অনির্বাচিত কিনা তার উপর ভিত্তি করে তার চেহারা পরিবর্তন করে।
@Preview@ComposablefunToggleIconButtonExample(){// isToggled initial value should be read from a view model or persistent storage.varisToggledbyrememberSaveable{mutableStateOf(false)}IconButton(onClick={isToggled=!isToggled}){Icon(painter=if(isToggled)painterResource(R.drawable.favorite_filled)elsepainterResource(R.drawable.favorite),contentDescription=if(isToggled)"Selected icon button"else"Unselected icon button.")}}
ToggleIconButtonExample composable একটি টগলযোগ্য IconButton সংজ্ঞায়িত করে।
mutableStateOf(false) একটি MutableState অবজেক্ট তৈরি করে যা একটি বুলিয়ান মান ধারণ করে, প্রাথমিকভাবে false । এটি isToggled একটি স্টেট হোল্ডার করে, যার অর্থ কম্পোজ UI কে পুনরায় কম্পোজ করে যখনই এর মান পরিবর্তন হয়।
rememberSaveable নিশ্চিত করে যে স্ক্রীন রোটেশনের মতো কনফিগারেশন পরিবর্তন জুড়ে isToggled অবস্থা বজায় থাকে।
IconButton এর onClick lambda ক্লিক করার সময় বোতামের আচরণকে সংজ্ঞায়িত করে, true এবং false মধ্যে অবস্থা টগল করে।
Icon কম্পোজেবলের painter প্যারামিটার শর্তসাপেক্ষে isToggled অবস্থার উপর ভিত্তি করে একটি ভিন্ন painterResource লোড করে। এটি আইকনের চাক্ষুষ চেহারা পরিবর্তন করে।
যদি isToggledtrue হয়, এটি ভরাট হৃদয় লোড করে আঁকা যায়।
যদি isToggledfalse হয়, তাহলে এটি আউটলাইন করা হৃদয়কে লোড করে।
উপযুক্ত অ্যাক্সেসিবিলিটি তথ্য প্রদানের জন্য IconcontentDescriptionisToggled অবস্থার উপর ভিত্তি করে আপডেট হয়।
ফলাফল
নিম্নলিখিত চিত্রটি তার অনির্বাচিত অবস্থায় পূর্ববর্তী স্নিপেট থেকে টগল আইকন বোতামটি দেখায়:
চিত্র 2. একটি "প্রিয়" টগল আইকন বোতাম তার অনির্বাচিত অবস্থায়।
উন্নত উদাহরণ: প্রেসে বারবার অ্যাকশন
এই বিভাগটি প্রদর্শন করে যে কীভাবে আইকন বোতামগুলি তৈরি করতে হয় যা ক্রমাগত একটি অ্যাকশন ট্রিগার করে যখন ব্যবহারকারী তাদের টিপে এবং ধরে রাখে, প্রতি ক্লিকে একবার ট্রিগার করার পরিবর্তে।
@ComposablefunMomentaryIconButton(unselectedImage:Int,selectedImage:Int,contentDescription:String,modifier:Modifier=Modifier,stepDelay:Long=100L,// Minimum value is 1L milliseconds.onClick:()->Unit){valinteractionSource=remember{MutableInteractionSource()}valisPressedbyinteractionSource.collectIsPressedAsState()valpressedListenerbyrememberUpdatedState(onClick)LaunchedEffect(isPressed){while(isPressed){delay(stepDelay.coerceIn(1L,Long.MAX_VALUE))pressedListener()}}IconButton(modifier=modifier,onClick=onClick,interactionSource=interactionSource){Icon(painter=if(isPressed)painterResource(id=selectedImage)elsepainterResource(id=unselectedImage),contentDescription=contentDescription,)}}
MomentaryIconButton একটি unselectedImage: Int , বোতাম টিপলে আইকনের জন্য অঙ্কনযোগ্য রিসোর্স আইডি এবং বাটনটি চাপলে আইকনের জন্য অঙ্কনযোগ্য রিসোর্স আইডি selectedImage: Int ।
এটি ব্যবহারকারীর কাছ থেকে বিশেষভাবে "প্রেস" ইন্টারঅ্যাকশন ট্র্যাক করতে একটি interactionSource ব্যবহার করে।
isPressed সত্য যখন বোতাম সক্রিয়ভাবে চাপা হয় এবং অন্যথায় মিথ্যা হয়। যখন isPressedtrue হয়, তখন LaunchedEffect একটি লুপে প্রবেশ করে।
এই লুপের ভিতরে, এটি ট্রিগারিং অ্যাকশনগুলির মধ্যে বিরতি তৈরি করতে একটি delay ( stepDelay সহ) ব্যবহার করে। coerceIn অসীম লুপ প্রতিরোধ করতে বিলম্ব কমপক্ষে 1ms নিশ্চিত করে।
লুপের মধ্যে প্রতিটি বিলম্বের পরে pressedListener আহ্বান করা হয়। এটি কর্ম পুনরাবৃত্তি করে তোলে.
onClick lambda (সঞ্চালনের ক্রিয়া) সর্বদা সর্বশেষ রচনা থেকে সবচেয়ে আপ-টু-ডেট তা নিশ্চিত করতে pressedListenerrememberUpdatedState ব্যবহার করে।
Icon বর্তমানে বোতাম টিপছে কি না তার উপর ভিত্তি করে প্রদর্শিত চিত্র পরিবর্তন করে।
যদি isPressed সত্য হয়, selectedImage দেখানো হয়।
অন্যথায়, unselectedImage দেখানো হয়।
পরবর্তী, একটি উদাহরণে এই MomentaryIconButton ব্যবহার করুন। নিম্নলিখিত স্নিপেট একটি কাউন্টার নিয়ন্ত্রণ করে দুটি আইকন বোতাম প্রদর্শন করে:
@Preview()@ComposablefunMomentaryIconButtonExample(){varpressedCountbyremember{mutableIntStateOf(0)}Row(modifier=Modifier.fillMaxWidth(),verticalAlignment=Alignment.CenterVertically){MomentaryIconButton(unselectedImage=R.drawable.fast_rewind,selectedImage=R.drawable.fast_rewind_filled,stepDelay=100L,onClick={pressedCount-=1},contentDescription="Decrease count button")Spacer(modifier=Modifier)Text("advanced by $pressedCount frames")Spacer(modifier=Modifier)MomentaryIconButton(unselectedImage=R.drawable.fast_forward,selectedImage=R.drawable.fast_forward_filled,contentDescription="Increase count button",stepDelay=100L,onClick={pressedCount+=1})}}
MomentaryIconButtonExample কম্পোজেবল দুটি MomentaryIconButton দৃষ্টান্ত সহ একটি Row প্রদর্শন করে এবং একটি কাউন্টার বৃদ্ধি এবং হ্রাস করার জন্য একটি UI তৈরি করার জন্য একটি Text কম্পোজযোগ্য।
এটি remember এবং mutableIntStateOf ব্যবহার করে একটি pressedCount মিউটেবল স্টেট ভেরিয়েবল বজায় রাখে, 0 এ আরম্ভ করা হয়। যখন pressedCount পরিবর্তিত হয়, তখন যেকোন কম্পোজেবল এটিকে পর্যবেক্ষণ করে (যেমন Text কম্পোজেবল) নতুন মান প্রতিফলিত করতে পুনরায় কম্পোজ করে।
প্রথম MomentaryIconButton ক্লিক করা বা রাখা হলে pressedCount কমে যায়।
দ্বিতীয় MomentaryIconButton ক্লিক করা বা রাখা হলে pressedCount বৃদ্ধি করে।
উভয় বোতাম 100 মিলিসেকেন্ডের একটি stepDelay ব্যবহার করে, যার অর্থ একটি বোতাম রাখা অবস্থায় onClick অ্যাকশনটি প্রতি 100 মিলিমিটারে পুনরাবৃত্তি হয়।
ফলাফল
নিম্নলিখিত ভিডিওটি আইকন বোতাম এবং কাউন্টার সহ UI দেখায়:
চিত্র 3 । দুটি আইকন বোতাম (প্লাস এবং বিয়োগ) সহ একটি কাউন্টার UI যা কাউন্টারটিকে বৃদ্ধি এবং হ্রাস করে।
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-08-28 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-08-28 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["Icon buttons display actions that users can take. Icon buttons must use an icon\nwith a clear meaning, and typically represent common or frequently used actions.\n\nThere are two types of icon buttons:\n\n- **Default**: These buttons can open other elements, such as a menu or search.\n- **Toggle**: These buttons can represent binary actions that can be toggled on or off, such as \"favorite\" or \"bookmark\".\n\n**Figure 1.** Icon buttons, some of which are filled (indicating selection) and outlined.\n\nAPI surface\n\nUse the [`IconButton`](/reference/kotlin/androidx/compose/material3/package-summary#IconButton(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.IconButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function1)) composable to implement standard icon buttons. To\ncreate different visual styles like filled, filled tonal, or outlined, use\n[`FilledIconButton`](/reference/kotlin/androidx/compose/material3/package-summary#FilledIconButton(kotlin.Function0,androidx.compose.material3.IconButtonShapes,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.IconButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)), [`FilledTonalIconButton`](/reference/kotlin/androidx/compose/material3/package-summary#FilledTonalIconButton(kotlin.Function0,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.ui.graphics.Shape,androidx.compose.material3.IconButtonColors,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)), and\n[`OutlinedIconButton`](/reference/kotlin/androidx/compose/material3/package-summary#OutlinedIconButton(kotlin.Function0,androidx.compose.material3.IconButtonShapes,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.IconButtonColors,androidx.compose.foundation.BorderStroke,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function0)), respectively.\n\nThe key parameters for `IconButton` include:\n\n- `onClick`: A lambda function that executes when the user taps the icon button.\n- `enabled`: A boolean that controls the enabled state of the button. When `false`, the button does not respond to user input.\n- `content`: The composable content inside the button, typically an `Icon`.\n\nBasic example: Toggle icon button\n\nThis example shows you how to implement a toggle icon button. A toggle icon\nbutton changes its appearance based on whether it's selected or unselected.\n\n\n```kotlin\n@Preview\n@Composable\nfun ToggleIconButtonExample() {\n // isToggled initial value should be read from a view model or persistent storage.\n var isToggled by rememberSaveable { mutableStateOf(false) }\n\n IconButton(\n onClick = { isToggled = !isToggled }\n ) {\n Icon(\n painter = if (isToggled) painterResource(R.drawable.favorite_filled) else painterResource(R.drawable.favorite),\n contentDescription = if (isToggled) \"Selected icon button\" else \"Unselected icon button.\"\n )\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/IconButton.kt#L44-L58\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- The `ToggleIconButtonExample` composable defines a toggleable `IconButton`.\n - `mutableStateOf(false)` creates a `MutableState` object that holds a boolean value, initially `false`. This makes `isToggled` a state holder, meaning Compose recomposes the UI whenever its value changes.\n - `rememberSaveable` ensures the `isToggled` state persists across configuration changes, like screen rotation.\n- The `onClick` lambda of the `IconButton` defines the button's behavior when clicked, toggling the state between `true` and `false`.\n- The [`Icon`](/reference/kotlin/androidx/compose/material3/package-summary#Icon(androidx.compose.ui.graphics.painter.Painter,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.graphics.Color)) composable's `painter` parameter conditionally loads a different `painterResource` based on the `isToggled` state. This changes the visual appearance of the icon.\n - If `isToggled` is `true`, it loads the filled heart drawable.\n - If `isToggled` is `false`, it loads the outlined heart drawable.\n- The `contentDescription` of the `Icon` also updates based on the `isToggled` state to provide appropriate accessibility information.\n\nResult\n\nThe following image shows the toggle icon button from the preceding snippet in\nits unselected state:\n**Figure 2.** A \"favorite\" toggle icon button in its unselected state.\n\nAdvanced example: Repeated actions on press\n\nThis section demonstrates how to create icon buttons that continuously trigger\nan action while the user presses and holds them, rather than just triggering\nonce per click.\n\n\n```kotlin\n@Composable\nfun MomentaryIconButton(\n unselectedImage: Int,\n selectedImage: Int,\n contentDescription: String,\n modifier: Modifier = Modifier,\n stepDelay: Long = 100L, // Minimum value is 1L milliseconds.\n onClick: () -\u003e Unit\n) {\n val interactionSource = remember { MutableInteractionSource() }\n val isPressed by interactionSource.collectIsPressedAsState()\n val pressedListener by rememberUpdatedState(onClick)\n\n LaunchedEffect(isPressed) {\n while (isPressed) {\n delay(stepDelay.coerceIn(1L, Long.MAX_VALUE))\n pressedListener()\n }\n }\n\n IconButton(\n modifier = modifier,\n onClick = onClick,\n interactionSource = interactionSource\n ) {\n Icon(\n painter = if (isPressed) painterResource(id = selectedImage) else painterResource(id = unselectedImage),\n contentDescription = contentDescription,\n )\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/IconButton.kt#L62-L92\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- `MomentaryIconButton` takes an `unselectedImage: Int`, the drawable resource ID for the icon when the button is not pressed, and `selectedImage: Int`, the drawable resource ID for the icon when the button is pressed.\n- It uses an `interactionSource` to specifically track \"press\" interactions from the user.\n- `isPressed` is true when the button is actively being pressed and false otherwise. When `isPressed` is `true`, the `LaunchedEffect` enters a loop.\n - Inside this loop, it uses a `delay` (with `stepDelay`) to create pauses between triggering actions. `coerceIn` ensures the delay is at least 1ms to prevent infinite loops.\n - The `pressedListener` is invoked after each delay within the loop. This makes the action repeat.\n- The `pressedListener` uses `rememberUpdatedState` to ensure that the `onClick` lambda (the action to perform) is always the most up-to-date from the latest composition.\n- The `Icon` changes its displayed image based on whether the button is currently pressed or not.\n - If `isPressed` is true, the `selectedImage` is shown.\n - Otherwise, the `unselectedImage` is shown.\n\nNext, use this `MomentaryIconButton` in an example. The following snippet\ndemonstrates two icon buttons controlling a counter:\n\n\n```kotlin\n@Preview()\n@Composable\nfun MomentaryIconButtonExample() {\n var pressedCount by remember { mutableIntStateOf(0) }\n\n Row(\n modifier = Modifier.fillMaxWidth(),\n verticalAlignment = Alignment.CenterVertically\n ) {\n MomentaryIconButton(\n unselectedImage = R.drawable.fast_rewind,\n selectedImage = R.drawable.fast_rewind_filled,\n stepDelay = 100L,\n onClick = { pressedCount -= 1 },\n contentDescription = \"Decrease count button\"\n )\n Spacer(modifier = Modifier)\n Text(\"advanced by $pressedCount frames\")\n Spacer(modifier = Modifier)\n MomentaryIconButton(\n unselectedImage = R.drawable.fast_forward,\n selectedImage = R.drawable.fast_forward_filled,\n contentDescription = \"Increase count button\",\n stepDelay = 100L,\n onClick = { pressedCount += 1 }\n )\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/IconButton.kt#L96-L123\n```\n\n\u003cbr /\u003e\n\nKey points about the code\n\n- The `MomentaryIconButtonExample` composable displays a `Row` containing two `MomentaryIconButton` instances and a `Text` composable to build a UI for incrementing and decrementing a counter.\n- It maintains a `pressedCount` mutable state variable using `remember` and `mutableIntStateOf`, initialized to 0. When `pressedCount` changes, any composables observing it (like the `Text` composable) recompose to reflect the new value.\n- The first `MomentaryIconButton` decreases `pressedCount` when clicked or held.\n- The second `MomentaryIconButton` increases `pressedCount` when clicked or held.\n- Both buttons use a `stepDelay` of 100 milliseconds, meaning the `onClick` action repeats every 100ms while a button is held.\n\nResult\n\nThe following video shows the UI with the icon buttons and the counter:\n**Figure 3**. A counter UI with two icon buttons (plus and minus) that increment and decrement the counter.\n\nAdditional resources\n\n- [Material 3 - Icon buttons](https://m3.material.io/components/icon-buttons/overview)"]]