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 MainBottomUnSelectColor = Color(0xFFA9AEBD)
|
||||||
|
|
||||||
//标题颜色
|
//标题颜色
|
||||||
val headBgColor = Color(0xFF3D4B7C)
|
var headBgColor = Color(0xFF3D4B7C)
|
||||||
|
|
||||||
//标题颜色
|
//标题颜色
|
||||||
val headTitleColor = Color(0xB3FFFFFF)
|
val headTitleColor = Color(0xB3FFFFFF)
|
||||||
|
@ -20,6 +20,7 @@ import androidx.core.view.ViewCompat
|
|||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
|
||||||
private val LightColorScheme = lightColorScheme(
|
private val LightColorScheme = lightColorScheme(
|
||||||
primary = Purple40,
|
primary = Purple40,
|
||||||
@ -31,10 +32,7 @@ private val LightColorScheme = lightColorScheme(
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun DealerTheme(
|
fun DealerTheme(darkTheme : Boolean = isSystemInDarkTheme(), content : @Composable () -> Unit) {
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
|
||||||
content: @Composable () -> Unit
|
|
||||||
) {
|
|
||||||
val colorScheme = when {
|
val colorScheme = when {
|
||||||
darkTheme -> LightColorScheme
|
darkTheme -> LightColorScheme
|
||||||
else -> LightColorScheme
|
else -> LightColorScheme
|
||||||
@ -49,18 +47,27 @@ fun DealerTheme(
|
|||||||
ViewCompat.setOnApplyWindowInsetsListener(window.decorView.findViewById(android.R.id.content)) { view, windowInsets ->
|
ViewCompat.setOnApplyWindowInsetsListener(window.decorView.findViewById(android.R.id.content)) { view, windowInsets ->
|
||||||
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
view as ViewGroup
|
view as ViewGroup
|
||||||
|
view.setBackgroundColor(headBgColor.toArgb())
|
||||||
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
leftMargin = insets.left
|
leftMargin = insets.left
|
||||||
bottomMargin = insets.bottom
|
bottomMargin = insets.bottom
|
||||||
rightMargin = insets.right
|
rightMargin = insets.right
|
||||||
topMargin = 0
|
topMargin = 0
|
||||||
}
|
}
|
||||||
|
view.updatePadding(top = insets.top,
|
||||||
|
bottom = insets.bottom,
|
||||||
|
left = view.paddingLeft,
|
||||||
|
right = view.paddingRight)
|
||||||
WindowInsetsCompat.CONSUMED
|
WindowInsetsCompat.CONSUMED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MaterialTheme(colorScheme = colorScheme) {
|
MaterialTheme(colorScheme = colorScheme) {
|
||||||
CompositionLocalProvider(LocalRippleConfiguration provides RippleConfiguration(rippleAlpha = RippleAlpha(0f, 0f, 0f, 0f))) {
|
CompositionLocalProvider(LocalRippleConfiguration provides RippleConfiguration(rippleAlpha = RippleAlpha(
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f,
|
||||||
|
0f))) {
|
||||||
ProvideTextStyle(value = MaterialTheme.typography.bodyLarge, content = content)
|
ProvideTextStyle(value = MaterialTheme.typography.bodyLarge, content = content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package com.za.base.view
|
package com.za.base.view
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.systemBarsPadding
|
|
||||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@ -18,37 +16,37 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import com.za.base.theme.headBgColor
|
import com.za.base.theme.headBgColor
|
||||||
import com.za.base.theme.headPadding
|
|
||||||
import com.za.servicing.R
|
import com.za.servicing.R
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun HeadView(title: String, onBack: () -> Unit = {}, isCanBack: Boolean = true, action: @Composable () -> Unit = {}) {
|
fun HeadView(title : String,
|
||||||
CenterAlignedTopAppBar(modifier = Modifier
|
onBack : () -> Unit = {},
|
||||||
.fillMaxWidth()
|
isCanBack : Boolean = true,
|
||||||
.background(color = headBgColor)
|
action : @Composable () -> Unit = {}) {
|
||||||
.systemBarsPadding()
|
CenterAlignedTopAppBar(modifier = Modifier.fillMaxWidth(),
|
||||||
.padding(top = 20.dp),
|
colors = TopAppBarDefaults.centerAlignedTopAppBarColors()
|
||||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors().copy(containerColor = headBgColor, titleContentColor = Color.White),
|
.copy(containerColor = headBgColor, titleContentColor = Color.White),
|
||||||
title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) },
|
title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
if (isCanBack) {
|
if (isCanBack) {
|
||||||
AsyncImage(model = R.drawable.sv_back, contentDescription = "", modifier = Modifier
|
AsyncImage(model = R.drawable.sv_back,
|
||||||
|
contentDescription = "",
|
||||||
|
modifier = Modifier
|
||||||
.size(40.dp)
|
.size(40.dp)
|
||||||
.clickable { onBack() }
|
.clickable { onBack() }
|
||||||
.padding(10.dp))
|
.padding(10.dp))
|
||||||
}
|
}
|
||||||
}, actions = { action() })
|
},
|
||||||
|
actions = { action() })
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun HeadViewNotBack(title : String) {
|
fun HeadViewNotBack(title : String) {
|
||||||
CenterAlignedTopAppBar(modifier = Modifier
|
CenterAlignedTopAppBar(modifier = Modifier.fillMaxWidth(),
|
||||||
.fillMaxWidth()
|
colors = TopAppBarDefaults.centerAlignedTopAppBarColors()
|
||||||
.background(color = headBgColor)
|
.copy(containerColor = headBgColor, titleContentColor = Color.White),
|
||||||
.padding(top = headPadding),
|
|
||||||
colors = TopAppBarDefaults.centerAlignedTopAppBarColors().copy(containerColor = headBgColor, titleContentColor = Color.White),
|
|
||||||
title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) },
|
title = { Text(text = title, fontSize = 15.sp, fontWeight = FontWeight.Medium) },
|
||||||
navigationIcon = {})
|
navigationIcon = {})
|
||||||
}
|
}
|
Reference in New Issue
Block a user