当前位置:网站首页>Jetpack compose scaffold and topappbar (top navigation)
Jetpack compose scaffold and topappbar (top navigation)
2022-06-11 02:29:00 【ScottePerk】
Jetpack Compose hereinafter referred to as JC
JC Provides Scaffold This component is used to realize some navigation effects , E.g. top menu , Bottom navigation , Next to the drawer menu and so on ,Scaffold Scaffolding means scaffolding , That is to say Scaffold This is a bracket provided , Or fix the position of some control implementation . The following is achieved by TopAppBar To illustrate .
TopAppBar There are two ways to do it , The following is an implementation .
@Composable
public fun TopAppBar(
title: @Composable () -> Unit,
modifier: Modifier,
navigationIcon: @Composable() (() -> Unit)?,
actions: @Composable() (RowScope.() -> Unit),
backgroundColor: Color,
contentColor: Color,
elevation: Dp
): Unit
There is also a second implementation :
@Composable
public fun TopAppBar(
modifier: Modifier,
backgroundColor: Color,
contentColor: Color,
elevation: Dp,
contentPadding: PaddingValues,
content: @Composable() (RowScope.() -> Unit)
): Unit
The difference between the two ways is , The first method is the one that has been restricted , Inside Icon And the position of the text , The second method is actually a completely custom style , You need to set the position manually , in general , The first one is more convenient . Here's an example .
The first way :
Read notes , It's very clear , This way the title section is very easy to center , The second approach may be problematic .
TopAppBar(
// title
title = {
Text(
modifier = Modifier.fillMaxSize().wrapContentSize(Alignment.Center),
text = "TODO"
)
},
// Navigation button , Generally, it is a return button
navigationIcon = {
IconButton(onClick = {
println(" return ") }) {
Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null)
}
},
// Other buttons
actions = {
IconButton(onClick = {
println(" Share ") }) {
Icon(imageVector = Icons.Default.Share, contentDescription = null)
}
IconButton(onClick = {
println(" Set up ") }) {
Icon(imageVector = Icons.Default.Settings, contentDescription = null)
}
},
// Background color
backgroundColor = Color(0xffffffaa),
// Content color
contentColor = Color.Black,
// Bottom shadow
elevation = 5.dp
)

The second method needs to completely customize the control , Especially the title Text Of fillMaxWidth() Method , If set to 1.0f, Then the button on the left will not be visible , If you write a scale like 0.8 There may also be position deviation , It is still difficult to control , You may need other constraint controls to constrain the position , That would be much more troublesome than the first way .
TopAppBar(contentColor = Color.Black, backgroundColor = Color.Red) {
// Return button
IconButton(onClick = {
}) {
Icon(Icons.Filled.ArrowBack, null)
}
Text(text = "TODO", modifier = Modifier.fillMaxWidth(0.9f).wrapContentSize(Alignment.Center))
IconButton(onClick = {
println(" Share ") }) {
Icon(Icons.Default.Share, null)
}
IconButton(onClick = {
println(" Set up ") }) {
Icon(Icons.Default.Settings, null)
}
}

边栏推荐
- MOFs, metal organic framework materials of folic acid ligands, are loaded with small molecule drugs such as 5-fluorouracil, sidabelamine, taxol, doxorubicin, daunorubicin, ibuprofen, camptothecin, cur
- Setting access to win10 shared folder without verification
- 环糊精金属有机骨架(β-CD-MOF)装载二巯丁二酸/大黄素/槲皮素/三氯蔗糖/二氟尼柳/奥美拉唑(OME)
- 如何保障数仓数据质量?
- Metal organic framework MOF Al (Diba), MOF Zr (Diba), MOF Fe (Diba) loaded with curcumin / carboxybenzylpenicillin /mtx methotrexate / paclitaxel ptx/ DOX / cisplatin cddp/cpt camptothecin and other d
- Project records
- Jetpack Compose Box控件
- [3.delphi common components] 8 dialog box
- The interviewer of Tencent said that who knows the internal module index principle and performance optimization idea of MySQL architecture?
- 1031. 两个非重叠子数组的最大和
猜你喜欢

When a logical deletion encounters a unique index, what are the problems and solutions?

ShaderGraphs

To view the data in redis, in addition to the command line and client, you have a third option

koa2学习笔记

Find - (half find / half find)

Metal organic framework materials (fe-mil-53, mg-mof-74, ti-kumof-1, fe-mil-100, fe-mil-101) supported on isoflurane / methotrexate / doxorubicin (DOX) / paclitaxel / ibuprofen / camptothecin

Analysis of the difficulties in the architecture design of massive chat messages in the live broadcast room

SQL | 计算总和

Jetpack Compose Scaffold和TopAppBar(顶部导航)

Multilevel mesoporous organometallic framework material zif-8 loaded with lactic acid oxidase (LOD) / ferric oxide (Fe304) / doxorubicin / insulin /cas9 protein / metronidazole / emodin methyl ether
随机推荐
技术分享| 快对讲,全球对讲
安全生产月知识竞赛——新安法知多少
During SSH configuration key login, you need to pay attention to whether the private key is set with a password
叶酸配体的金属有机骨架材料MOFs负载5-氟尿嘧啶,西达本胺,紫杉醇,阿霉素,柔红霉素,布洛芬,喜树碱,姜黄素,藤黄酸等小分子药物
English subtitle video translated into Chinese subtitles
[3.delphi common components] 7 timer
Web watermark
2022 high altitude installation, maintenance and removal of simulated examination platform of theoretical question bank
Do tween record
In the past 10 years, from zero foundation testing to test architect, he has made himself successful
Unity3d model skin changing technology
The largest kth element in the array
421. 数组中两个数的最大异或值
SQL | calculate sum
Why is the trend chart of precious metal silver strong?
MySQL备份与恢复
C language principle explanation and code implementation of scalable / reduced thread pool
贵金属白银行情走势图缘何强势?
Unity3d detects that the object is not within the range of the camera
Redis learning notes (continuously updating)