英文:
I am trying to create TabRow with android compose kotlin. I couldn't add background color to tabrow. How can i do that?
问题
The issue you're facing with the red background color may be related to the Malibu
color you're using. Make sure you have imported the correct color or defined it properly. Double-check your imports and ensure that the color you intend to use is correctly defined.
Also, based on the code snippet you provided, it seems like you're using ButtomNavigationTheme
, which might be a custom theme. Ensure that this theme is correctly set up and includes the necessary color definitions.
If you're still facing issues, you might want to check the definition of the Malibu
color and see if it's set to the color you desire.
英文:
class MainActivity : ComponentActivity() {
@OptIn(ExperimentalFoundationApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val tabItems = listOf("Diziler", "Filmler", "Keşfet", "Profil")
val pagerState = rememberPagerState()
ButtomNavigationTheme {
// A surface container using the 'background' color from the theme
Surface(){
Column() {
TabRow(
selectedTabIndex = pagerState.currentPage,
backgroundColor = Malibu,
//PROBLEM IN HERE. BACKGROUNDCOLOR IS RED
modifier = Modifier.padding(all = 20.dp).background(color = Color.Transparent)
){
}
background color = Malibu is red. Do I miss to import something?
I dont know what to do. Or can I do this in a different way?
this is the image of red error
these are my imports. I couldnt add in code because it was too long for the stackoverflow
答案1
得分: 0
你需要分别指定containerColor
和contentColor
。Material3版本的TabRow
中没有backgroundColor
。
@Composable
fun TabRow(
selectedTabIndex: Int,
modifier: Modifier = Modifier,
containerColor: Color = TabRowDefaults.containerColor,
contentColor: Color = TabRowDefaults.contentColor,
...
): Unit
英文:
You have to specify the containerColor
and contententColor
separately. There is no backgroundColor
in the Material3 version of TabRow
.
@Composable
fun TabRow(
selectedTabIndex: Int,
modifier: Modifier = Modifier,
containerColor: Color = TabRowDefaults.containerColor,
contentColor: Color = TabRowDefaults.contentColor,
...
): Unit
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论