Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose: "Unresolved reference: BottomNavigation"

My MainActivity looks this way:

class MainActivity : ComponentActivity() {
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@OptIn(ExperimentalMaterial3Api::class)
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContent {
        BottomNavTheme {
            Scaffold(bottomBar = {
                BottomNavigation(
                    backgroundColor = colorResource(id = R.color.teal_200),
                    contentColor = Color.Black
                ) {

                }
            }) {
                
            }
        }
    }
}

}

The code should be alright, I guess. But it results in an "Unresolved reference:"-error

error-message

I have implemented that functionality in the past already. It wasn't that hard to do.

What goes wrong here? How can the issue become fixed?

Have there been changes? I'm using the very new Android Studio Flamingo.

like image 966
a.hess Avatar asked Feb 02 '26 16:02

a.hess


2 Answers

Renamed to NavigationBar in m3.

For more information about the changes in the new version of the material, refer to the following link:

Migrate from Material 2 to Material 3 in Compose

like image 57
elias sharafi Avatar answered Feb 05 '26 06:02

elias sharafi


Make sure that:

  1. You added this dependency in your app module's build.gradle file:

    implementation "androidx.compose.material:material:1.4.2"
    
  2. You imported androidx.compose.material.BottomNavigation in your MainActivity.kt file.

If you did all these steps below, the error has to be disappeared. If it is not, try to invalidate caches and restart Android Studio:

File -> Invalidate caches -> [Mark all options such as clear file system cache etc.] -> Invalidate & Restart
like image 36
Mikhail Guliaev Avatar answered Feb 05 '26 07:02

Mikhail Guliaev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!