这是我的代码:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
YourProjectNameTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background
) {
Column(modifier = Modifier.fillMaxSize()) {
MyUI()
}
}
}
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MyUI() {
val contextForToast = LocalContext.current.applicationContext
LargeTopAppBar(
title = { Text(text = "SemicolonSpace") },
navigationIcon = {
IconButton(onClick = {
Toast.makeText(contextForToast, "Nav Icon Click", Toast.LENGTH_SHORT).show()
}) {
Icon(imageVector = Icons.Filled.Menu, contentDescription = "Menu")
}
},
actions = {
IconButton(onClick = {
Toast.makeText(contextForToast, "Add Click", Toast.LENGTH_SHORT).show()
}) {
Icon(imageVector = Icons.Default.Add, contentDescription = "Add Items")
}
},
colors = TopAppBarDefaults.largeTopAppBarColors(
containerColor = Color.Green.copy(alpha = 0.3f)
)
)
}
这是输出:
正如你所看到的,颜色没有应用到标题上。它仅适用于图标部分。我也得到了这个问题与中等顶部应用程序栏太,但不是与中心和小应用程序栏。我做错什么了吗?还是设计指南
以下是我正在使用的gradle文件:
项目级gradle文件:
plugins {
id 'com.android.application' version '8.0.1' apply false
id 'com.android.library' version '8.0.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
应用级gradle文件:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'com.example.yourprojectname'
compileSdk 33
defaultConfig {
applicationId "com.example.yourprojectname"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.3.2'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.5.1'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2022.10.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
}
- 修复:**
没有解决办法。这个bug是reported here。我试着用background()
修改器改变版本。什么都不管用。唯一的解决方案是使用Surface()
或Box()
可组合项创建自定义应用程序栏。
1条答案
按热度按时间euoag5mw1#
尝试更新版本的材料3,我使用的材料3版本
1.0.0-alpha11
和它的工作:结果如下: