Row如何更改Jetpack Compose 中边框的形状?
我正在 jetpack compose 中创建一个自定义按钮,为此我使用 aRow来水平对齐内容。我需要这个自定义按钮具有以下格式:
但是,我在 compose 中的代码呈现以下元素,没有圆角边缘:
该撰写功能的代码如下:
@Composable
fun LargeQuantityButton(
modifier: Modifier = Modifier,
onPlusClick: () -> Unit,
onMinusClick: () -> Unit,
text: String,
) = Row(
modifier = modifier
.border(
border = ButtonDefaults.outlinedBorder,
shape = RoundedCornerShape(4.dp)
),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
RemoveIcon(action = onMinusClick)
Text(
text = text,
fontWeight = FontWeight.W400
)
AddIcon(action = onPlusClick)
}
Run Code Online (Sandbox Code Playgroud)
我尝试clip在调用后立即添加函数调用,border如下所示Modifier:
@Composable
fun …Run Code Online (Sandbox Code Playgroud) 当我尝试使用以下命令进行提交时,我在提交时遇到问题,例如:
$ git commit -m "add readme"
pre-commit not found. Install pre-commit with the command pip3 install --user pre-commit or follow the steps on official documentation: https://pre-commit.com /#install
Run Code Online (Sandbox Code Playgroud)
按照我通过命令安装的预提交安装文档中描述的步骤:
$ pip install pre-commit
Run Code Online (Sandbox Code Playgroud)
但是,当我触发命令时,会发生以下错误:
$ pre-commit --version
bash: pre-commit: command not found
Run Code Online (Sandbox Code Playgroud)
我的尝试失败了,所以我尝试了一些其他解决方案,但它们不起作用。
我已经尝试过所描述的解决方案,即使用~./bashrc命令导出我的:source ~/.profile但出现以下错误:
bash:/Users/pvieira/.profile: No such file or directory
Run Code Online (Sandbox Code Playgroud)
这会导致与上述手动安装时发生的错误相同的错误pip。
// Coil
implementation "io.coil-kt:coil-compose:1.4.0"
Run Code Online (Sandbox Code Playgroud)
以前我将线圈与 Google 一起使用,但是当我按照文档所示accompanist迁移到新版本的线圈时,我遇到了该方法的问题:target
// Coil
implementation "io.coil-kt:coil-compose:1.4.0"
Run Code Online (Sandbox Code Playgroud)
当浏览(线圈类)的内部代码时,ImagePainter您可以看到由于某种原因该target方法确实需要为 null:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pokedex, PID: 13502
java.lang.IllegalArgumentException: request.target must be null.
at coil.compose.ImagePainterKt.rememberImagePainter(ImagePainter.kt:94)
...
Run Code Online (Sandbox Code Playgroud)
这是我在 jetpack compose 中的组件(图像组件位于列内):
@Composable
fun rememberImagePainter(
request: ImageRequest,
imageLoader: ImageLoader,
onExecute: ExecuteCallback = ExecuteCallback.Default,
): ImagePainter {
requireSupportedData(request.data)
require(request.target == null) { "request.target must be null." }
...
Run Code Online (Sandbox Code Playgroud)
我需要目标方法viewModel根据drawable它作为参数传递的内容来执行内部操作。有人能帮我吗?
我正在使用新的谷歌地图集成库与 jetpack compose,但是我想修改我的标记的行为:当地图初始化时,我想显示我的标记的信息,而不必单击它。目前地图是这样开始的:
当我单击突出显示的标记时,它看起来像这样:
我期望的结果是该书签与此信息一起出现,而我不必单击它。
我用来渲染带有标记的地图的代码是这样的:
GoogleMap(
modifier = Modifier
.fillMaxHeight(0.9f)
.fillMaxWidth(),
cameraPositionState = cameraPositionState
) {
coordinates.forEach { (hotelName, coordinate) ->
var alpha = 0.5f
if (highlightedMarkerPosition == LatLng(coordinate[0], coordinate[1]))
alpha = 1f
Marker(
position = LatLng(coordinate[0], coordinate[1]),
title = hotelName,
snippet = uiState.bestHotelAndValue?.second.toString(),
alpha = alpha
)
}
}
Run Code Online (Sandbox Code Playgroud) 我正在为使用自定义视图的撰写函数创建一个抽象:
@Composable
fun DisposeBanner(bannerView: BannerView) {
DisposableEffect(key1 = true) {
onDispose {
bannerView.destroyAd()
}
}
}
Run Code Online (Sandbox Code Playgroud)
然而,由于这个函数实际上并不渲染任何组件,我不希望它坚持 @Composable 标记,而是表明它只能通过扩展在组合函数中使用。
当尝试这样做时:
fun Composable.disposeBanner(bannerView: BannerView) {
DisposableEffect(key1 = true) {
onDispose {
bannerView.destroyAd()
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:“@Composable 调用只能在 @Composable 函数的上下文中发生”
可以做我想做的事吗?
我的 android studio 停止显示“运行”按钮(在它显示该项目没有问题之前)。我尝试了几种解决方案,例如:“使缓存无效”、“将项目与 gradle 文件同步”和“尝试使用快捷键 shift + F10 运行”,但都不起作用。
所选模块正确。
Android Studio Bumblebee | 2021.1.1 Patch 2
Build #AI-211.7628.21.2111.8193401, built on February 17, 2022
Runtime version: 11.0.11+0-b60-7590822 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.3.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 12
Registry: external.system.auto.import.disabled=true, debugger.watches.in.variables=false
Non-Bundled Plugins: com.wakatime.intellij.plugin (13.1.14), org.jetbrains.kotlin (211-1.6.20-release-275-AS7442.40), com.developerphil.adbidea (1.6.4), org.intellij.plugins.markdown (211.7142.37)
Run Code Online (Sandbox Code Playgroud) 我想知道以下之间的区别:
var textFieldState = remember {
mutableStateOf("")
}
Run Code Online (Sandbox Code Playgroud)
和
var textFieldState by remember {
mutableStateOf("")
}
Run Code Online (Sandbox Code Playgroud)
与其他相比有什么优势吗?
我正在尝试使用最新版本的 jetpack compose 1.1.0-rc02,但某些依赖项返回错误:
Failed to resolve: androidx.compose.material:material:1.1.0-rc02
Failed to resolve: androidx.compose.ui:ui:1.1.0-rc02
Failed to resolve: androidx.compose.ui:ui-tooling:1.1.0-rc02
Failed to resolve: androidx.compose.ui:ui-tooling-preview:1.1.0-rc02
Failed to resolve: androidx.compose.ui:ui-test-junit4:1.1.0-rc02
Run Code Online (Sandbox Code Playgroud)
buildscript {
ext {
compose_version = '1.1.0-rc02'
kotlin_version = '1.6.10'
hilt_version = '2.38.1'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) …Run Code Online (Sandbox Code Playgroud) android ×6
kotlin ×3
bash ×1
coil ×1
crash ×1
git ×1
git-commit ×1
google-maps ×1
ide ×1
pre-commit ×1