当前位置:网站首页>Kotlin Compose 隐式传参 CompositionLocalProvider
Kotlin Compose 隐式传参 CompositionLocalProvider
2022-06-27 03:36:00 【安果移不动】
代码
package com.anguomob.jecpack.activity.compose.composition.local
import androidx.compose.foundation.layout.Column
import androidx.compose.material.ContentAlpha
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalContext
@Composable
fun CompositionSample2() {
MaterialTheme() {
Column() {
Text(text = "sadjkllllasdkljaskljdasjkldaskjldajlk")
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
Text(text = "sadjkllllasdkljaskljdasjkldaskjldajlk")
Text(text = "sadjkllllasdkljaskljdasjkldaskjldajlk")
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.disabled) {
DescendantExample()
}
}
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.disabled) {
DescendantExample()
}
}
}
}
@Composable
fun DescendantExample() {
Text(text = "sadjkllllasdkljaskljdasjkldaskjldajlk")
}样式

这个场景你很常用的有获取上下文
@Composable
fun FruitText(fruitSize: Int) {
val res = LocalContext.current.resources
val fruitText = res.getQuantityString(R.plurals.fruit_title, fruitSize)
Text(text = "${fruitSize} ${fruitText}")
}LocalContext.current

边栏推荐
- Easy to use plug-ins in idea
- ESP8266
- 2021:Passage Retrieval for Outside-KnowledgeVisual Question Answering通道检索的外部知识视觉问答
- 人群模拟
- Lodash get JS code implementation
- 2021:Beyond Question-Based Biases:Assessing Multimodal Shortcut Learning in Visual Question Answeri
- Cs5213 HDMI to VGA (with audio) single turn scheme, cs5213 HDMI to VGA (with audio) IC
- A^2=E | 方程的解 | 这个方程究竟能告诉我们什么
- 再探Handler(上)(Handler核心原理最全解析)
- MySql的开发环境
猜你喜欢
随机推荐
Solve the problem of error reporting in cherry pick submission
Products change the world
2022茶艺师(高级)上岗证题库模拟考试平台操作
Further exploration of handler (I) (the most complete analysis of the core principle of handler)
Nestjs environment variable configuration to solve the problem of how to inject services into interceptors
一文教你Kali信息收集
PAT甲级 1018 Public Bike Management
Quicksand painting simulator source code
2021:Beyond Question-Based Biases:Assessing Multimodal Shortcut Learning in Visual Question Answeri
再探Handler(下)(Handler核心原理最全解析)
455. distribute biscuits [distribution questions]
使用promise的基本功能【四、Promise源码】
发现一款 JSON 可视化工具神器,太爱了!
I found a JSON visualization tool artifact. I love it!
Anaconda3安装过程及安装后缺失大量文件,没有scripts等目录
Usage knowledge of mobile phones in new fields
Logarithm
2021:Graphhopper: Multi-Hop Scene Graph Reasoning for Visual Question Answering
Pat grade a 1026 table tennis
2021:AdaVQA: Overcoming Language Priors with Adapted Margin Cosine Loss∗自适应的边缘余弦损失解决语言先验

![Basic functions of promise [IV. promise source code]](/img/a0/8f28ec8951088b8e66e7079432f326.png)







