I am trying to create TabRow with android compose kotlin. I couldn't add background color to tabrow. How can i do that?

huangapple go评论58阅读模式
英文:

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

你需要分别指定containerColorcontentColorMaterial3版本的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

huangapple
  • 本文由 发表于 2023年5月11日 19:54:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76227377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定