简体   繁体   中英

Why Jetpack Compose AppBar overlaps its shadow

I want AppBar to display default shadow below bottom edge but appbar clips its shadow for some reason:

没有阴影的应用栏

View hierarchy captured from LayoutInspector:

2

My code:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyAppTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = Color.Cyan,
                ) {
                    Box {
                        TopAppBar(
                            title = { Text("AppBar title") }
                        )
                    }
                }
            }
        }
    }
}

Why AppBar shadow behave like this? Am I using it incorrectly? How can I fix this?

UPD : My bad - shadow works as expected. I just didn't check it properly. Default shadow is very hard to detect visually:

正确工作阴影的证明

Try to add to Box this code modifier = Modifier.fillMaxSize() . Box cuts your shadow in your code

Example (I added there a white color to see the shadow better)

Surface(
    modifier = Modifier.fillMaxSize(),
    color = Color.White,
) {
    Box(modifier = Modifier.fillMaxSize()) {
        TopAppBar(
            backgroundColor = Color.White,
            title = { Text("AppBar title") }
        )
    }
}

Result在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM