I'm using compose3 and dolphin Android Studio on Gruda Linux. All updated!
I have a @Composable
function called feed which just have a FilledTonalButton
.
For the content of FilledTonalButton
I'm giving the icons.rounded.Add
Whenever I'm building, it gives me
e: /home/kumar-p/Desktop/AndroidStudio/<app_name>/app/src/main/java/com/f/rateme/MainActivity.kt: (95, 27): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public val Icons.Rounded.Add: ImageVector defined in androidx.compose.material.icons.rounded
<app_name> = my app name, removed because of confidentiality.
However when I replace the Icon()
with Text()
, it works!
My dependencies:
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.compose.material3:material3:1.0.0-alpha02'
implementation "androidx.compose.material:material-icons-extended:$compose_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
My imports on MainActivity.kt
package com.<example>.rateme // <example> = my company name
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.*
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material3.*
//import androidx.compose.material.icons.Icons
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.<example>.<app_name>.ui.theme.AppTheme // <example> = my company name, <app_name> = name of curent app
The function:
@Composable
fun feed(page: String): String {
FilledTonalButton(
onClick = {/*TODO: Add onClick for feed - New Post*/},
enabled = true) {
Icon(
imageVector = Add,
"New Post"
)
}
return page // TODO: implement the changes of page variable
}
If you find any typo please update it or tell me to fix.
PS: This is my first time here and I have an almost zero experience on android development and Kotlin. I developed terminal apps and worked on ML kinda work in Python, C , C. So I may need more information in explanation. I started learning Android Development a week ago only.
Edit: You can ask me any more information.
Peace
CodePudding user response:
Just specify the actual imageVector like this,
Icon(
imageVector = Icons.Default.Add
"New Post"
)
but you will still get ambiguity error. Since based on your post it looks like you want to use material3, just remove this import
import androidx.compose.material.* // remove this
or if you still want to use them both, you'll then have to declare their fully qualified name on usage,
androidx.compose.material3.Icon(
imageVector = Icons.Default.Add,
"New Post"
)