refactor(servicing): 重构头部样式并优化主题配置
-将 headBgColor 从 val改为 var,以便于后续可能的动态修改 - 移除了 head.kt 中的 systemBarsPadding() 和多余的背景颜色设置 - 调整了 Theme.kt 中的窗口装饰和系统栏设置,优化了头部样式
This commit is contained in:
@ -16,7 +16,7 @@ val MainBottomSelectColor = Color(0xFF3D4B7C)
|
||||
val MainBottomUnSelectColor = Color(0xFFA9AEBD)
|
||||
|
||||
//标题颜色
|
||||
val headBgColor = Color(0xFF3D4B7C)
|
||||
var headBgColor = Color(0xFF3D4B7C)
|
||||
|
||||
//标题颜色
|
||||
val headTitleColor = Color(0xB3FFFFFF)
|
||||
|
@ -20,50 +20,57 @@ import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePadding
|
||||
|
||||
private val LightColorScheme = lightColorScheme(
|
||||
primary = Purple40,
|
||||
secondary = PurpleGrey40,
|
||||
tertiary = Pink40,
|
||||
background = bgColor,
|
||||
onBackground = bgColor,
|
||||
primary = Purple40,
|
||||
secondary = PurpleGrey40,
|
||||
tertiary = Pink40,
|
||||
background = bgColor,
|
||||
onBackground = bgColor,
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DealerTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val colorScheme = when {
|
||||
darkTheme -> LightColorScheme
|
||||
else -> LightColorScheme
|
||||
}
|
||||
val view = LocalView.current
|
||||
if (!view.isInEditMode) {
|
||||
SideEffect {
|
||||
val window = (view.context as Activity).window
|
||||
window.statusBarColor = Color.Transparent.toArgb()
|
||||
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(window.decorView.findViewById(android.R.id.content)) { view, windowInsets ->
|
||||
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
view as ViewGroup
|
||||
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
leftMargin = insets.left
|
||||
bottomMargin = insets.bottom
|
||||
rightMargin = insets.right
|
||||
topMargin = 0
|
||||
}
|
||||
WindowInsetsCompat.CONSUMED
|
||||
}
|
||||
}
|
||||
}
|
||||
MaterialTheme(colorScheme = colorScheme) {
|
||||
CompositionLocalProvider(LocalRippleConfiguration provides RippleConfiguration(rippleAlpha = RippleAlpha(0f, 0f, 0f, 0f))) {
|
||||
ProvideTextStyle(value = MaterialTheme.typography.bodyLarge, content = content)
|
||||
}
|
||||
}
|
||||
fun DealerTheme(darkTheme : Boolean = isSystemInDarkTheme(), content : @Composable () -> Unit) {
|
||||
val colorScheme = when {
|
||||
darkTheme -> LightColorScheme
|
||||
else -> LightColorScheme
|
||||
}
|
||||
val view = LocalView.current
|
||||
if (! view.isInEditMode) {
|
||||
SideEffect {
|
||||
val window = (view.context as Activity).window
|
||||
window.statusBarColor = Color.Transparent.toArgb()
|
||||
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = ! darkTheme
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(window.decorView.findViewById(android.R.id.content)) { view, windowInsets ->
|
||||
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||
view as ViewGroup
|
||||
view.setBackgroundColor(headBgColor.toArgb())
|
||||
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
leftMargin = insets.left
|
||||
bottomMargin = insets.bottom
|
||||
rightMargin = insets.right
|
||||
topMargin = 0
|
||||
}
|
||||
view.updatePadding(top = insets.top,
|
||||
bottom = insets.bottom,
|
||||
left = view.paddingLeft,
|
||||
right = view.paddingRight)
|
||||
WindowInsetsCompat.CONSUMED
|
||||
}
|
||||
}
|
||||
}
|
||||
MaterialTheme(colorScheme = colorScheme) {
|
||||
CompositionLocalProvider(LocalRippleConfiguration provides RippleConfiguration(rippleAlpha = RippleAlpha(
|
||||
0f,
|
||||
0f,
|
||||
0f,
|
||||
0f))) {
|
||||
ProvideTextStyle(value = MaterialTheme.typography.bodyLarge, content = content)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//object NoRippleTheme : RippleTheme {
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.za.base.view
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.systemBarsPadding
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Text
|
||||
@ -18,37 +16,37 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import coil.compose.AsyncImage
|
||||
import com.za.base.theme.headBgColor
|
||||
import com.za.base.theme.headPadding
|
||||
import com.za.servicing.R
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun HeadView(title: String, onBack: () -> Unit = {}, isCanBack: Boolean = true, action: @Composable () -> Unit = {}) {
|
||||
CenterAlignedTopAppBar(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(color = headBgColor)
|
||||
.systemBarsPadding()
|
||||
.padding(top = 20.dp),
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors().copy(containerColor = headBgColor, titleContentColor = Color.White),
|
||||
title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) },
|
||||
navigationIcon = {
|
||||
if (isCanBack) {
|
||||
AsyncImage(model = R.drawable.sv_back, contentDescription = "", modifier = Modifier
|
||||
.size(40.dp)
|
||||
.clickable { onBack() }
|
||||
.padding(10.dp))
|
||||
}
|
||||
}, actions = { action() })
|
||||
fun HeadView(title : String,
|
||||
onBack : () -> Unit = {},
|
||||
isCanBack : Boolean = true,
|
||||
action : @Composable () -> Unit = {}) {
|
||||
CenterAlignedTopAppBar(modifier = Modifier.fillMaxWidth(),
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors()
|
||||
.copy(containerColor = headBgColor, titleContentColor = Color.White),
|
||||
title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) },
|
||||
navigationIcon = {
|
||||
if (isCanBack) {
|
||||
AsyncImage(model = R.drawable.sv_back,
|
||||
contentDescription = "",
|
||||
modifier = Modifier
|
||||
.size(40.dp)
|
||||
.clickable { onBack() }
|
||||
.padding(10.dp))
|
||||
}
|
||||
},
|
||||
actions = { action() })
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun HeadViewNotBack(title: String) {
|
||||
CenterAlignedTopAppBar(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(color = headBgColor)
|
||||
.padding(top = headPadding),
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors().copy(containerColor = headBgColor, titleContentColor = Color.White),
|
||||
title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) },
|
||||
navigationIcon = {})
|
||||
fun HeadViewNotBack(title : String) {
|
||||
CenterAlignedTopAppBar(modifier = Modifier.fillMaxWidth(),
|
||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors()
|
||||
.copy(containerColor = headBgColor, titleContentColor = Color.White),
|
||||
title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) },
|
||||
navigationIcon = {})
|
||||
}
|
Reference in New Issue
Block a user