我试图在单击文本时向下滚动到特定 UI 元素的位置。
我的文本的代码是:
Text(
"What is autosaving?",
color = colorResource(id = R.color.text_highlight),
fontSize = with(LocalDensity.current) {
dimensionResource(id = R.dimen._11ssp).toSp()
},
fontFamily = FontFamily(
Font(R.font.poppins_regular)
),
modifier = Modifier.constrainAs(whatIsAutosaving) {
top.linkTo(glWhatIsAutoSaving)
start.linkTo(parent.start)
end.linkTo(parent.end)
},
)
Run Code Online (Sandbox Code Playgroud)
单击此文本后,我的屏幕应滚动到另一个文本的开始位置。另一个文本的代码是:
Text(
stringResource(id = R.string.autosave_info),
color = colorResource(id = R.color.bright_green),
fontSize = with(LocalDensity.current) {
dimensionResource(id = R.dimen._11ssp).toSp()
}, fontFamily = FontFamily(
Font(R.font.poppins_regular)
),
modifier = Modifier.constrainAs(autoSaveInfo) {
top.linkTo(glAutoSaveInfo)
start.linkTo(glLeft)
end.linkTo(glRight)
width = Dimension.fillToConstraints
},
)
Run Code Online (Sandbox Code Playgroud)
我该如何实现这一目标?
编辑:
我的屏幕的完整代码是:
@Composable
fun Autosave(navController: NavController) {
val query …
Run Code Online (Sandbox Code Playgroud) android scroll android-jetpack-compose android-jetpack-compose-layout android-compose-layout
我一直在尝试在 Jetpack compose 中实现导航抽屉。以下代码显示了一种简单的方法:
@Composable
fun ModalDrawerSample() {
val drawerState = rememberDrawerState(DrawerValue.Closed)
val scope = rememberCoroutineScope()
ModalDrawer(
drawerState = drawerState,
drawerContent = {
Column {
Text("Text in Drawer")
Button(onClick = {
scope.launch {
drawerState.close()
}
}) {
Text("Close Drawer")
}
}
},
content = {
Column {
Text("Text in Bodycontext")
Button(onClick = {
scope.launch {
drawerState.open()
}
}) {
Text("Click to open")
}
}
}
)
}
Run Code Online (Sandbox Code Playgroud)
但是如何使导航抽屉从右向左打开呢?
我试图实现我的 TextField 只能接受 10 位数字的要求,并且我使用了“rememberSaveable”,以便当用户导航到另一个屏幕然后返回到此屏幕时,在 TextField 中输入的数字不会丢失。
我使用过 RememberSaveable,例如:
通过 RememberSaveable 进行 var 查询 { mutableStateOf(TextFieldValue("")) }
然后我在 TextField 中使用它:
val maxChar = 10
TextField(
value = query,
onValueChange = {
if (it.text.length <= maxChar) query = it
},
label = {
Text(
"Name as on PAN Card",
color = colorResource(id = R.color.bright_green),
fontSize = with(LocalDensity.current) { dimensionResource(id = R.dimen._12ssp).toSp() },
fontFamily = FontFamily(Font(R.font.poppins_regular)),
textAlign = TextAlign.Left
)
},
interactionSource = interactionSource,
keyboardOptions = KeyboardOptions(keyboardType =KeyboardType.Number),
textStyle = TextStyle(
textAlign …
Run Code Online (Sandbox Code Playgroud) 我一直在使用 这个库在视图系统中实现轮播。如何在 Jetpack Compose 中实现轮播?
在传统视图系统中,我通过使用偏差/指南/权重/wrap_content/避免硬编码尺寸/在约束布局中相对于彼此放置视图、使用“sdp”和“ssp”等来处理响应能力。
如何使用 Jetpack Compose 创建响应式布局?我一直在寻找有关它的信息但无法找到。
请帮忙!
点击TextField
使用 Jetpack compose 创建的 时, 的标签会TextField
向上移动。我们如何禁用它?或者有没有其他方式可以像系统中TexField
一样工作,我们有提示,点击后就会消失?EditText
View
EditText
我正在尝试在可组合图像中使用 .9.png 文件:
Image(
painter = painterResource(id = R.drawable.shadow_faq),
contentDescription = "Faq card 1",
modifier = Modifier
.constrainAs(imgGeneral) {
top.linkTo(glImgGeneralTop)
bottom.linkTo(glImgBottom)
start.linkTo(glImgLeft)
end.linkTo(glImgRight)
height = Dimension.fillToConstraints
width = Dimension.fillToConstraints
}
)
Run Code Online (Sandbox Code Playgroud)
但这样做时我遇到了一个渲染问题:java.lang.IllegalArgumentException: Only VectorDrawables and rasterized asset types are supported ex. PNG, JPG
如何将 .9.png 文件与 Jetpack Compose 结合使用?
我有一个文本字段,其中不能超过 10 个字符,并且要求用户以“mm/dd/yyyy”格式输入日期。每当用户键入前 2 个字符时,我都会附加“/”,当用户键入接下来的 2 个字符时,我会再次附加“/”。
为了实现这一目标,我做了以下操作:
var maxCharDate = 10
TextField(
value = query2,
onValueChange = {
if (it.text.length <= maxCharDate) {
if (it.text.length == 2 || it.text.length == 5)
query2 = TextFieldValue(it.text + "/", selection = TextRange(it.text.length+1))
else
query2 = it
}
emailErrorVisible.value = false
},
label = {
Text(
"Date of Birth (mm/dd/yyyy)",
color = colorResource(id = R.color.bright_green),
fontFamily = FontFamily(Font(R.font.poppins_regular)),
fontSize = with(LocalDensity.current) { dimensionResource(id = R.dimen._12ssp).toSp() })
},
.
.
.
Run Code Online (Sandbox Code Playgroud)
它正在工作,只是附加的“/”在按退格键时不会被删除,而其他字符会被删除。
如何使按退格键时“/”也被删除?
android textfield android-jetpack-compose android-compose-textfield
尝试执行我的项目时出现以下错误:
错误:任务“:app:javaPreCompileDebug”执行失败。
现在必须显式声明注释处理器。发现编译类路径上的以下依赖项包含注释处理器。请将它们添加到annotationProcessor配置中。- butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1) 或者,设置 android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true 以继续之前的行为。请注意,此选项已弃用,并将在将来删除。 有关更多详细信息,请参阅 https://developer.android.com/r/tools/annotation-processor-error-message.html 。
请不要将此问题标记为重复,因为其他问题对此进行了重新评级,这里是针对 lombok,我没有使用它。
我正在尝试在 Jetpack 中创建一个带有下划线但没有任何其他边框或背景的 TextField。我该怎么做呢?
这是我当前使用的代码:
val query = remember {mutableStateOf("")}
TextField(
value = query.value,
onValueChange = { newValue -> query.value = newValue },
label={Text("Dummy", color = colorResource(id = R.color.fade_green))},
textStyle = TextStyle(
textAlign = TextAlign.Start,
color = colorResource(id = R.color.fade_green),
fontFamily = FontFamily(Font(R.font.poppins_regular)),
fontSize = 14.sp,
),
modifier = Modifier
.padding(start = 30.dp).border(0.dp, Color.Red),
colors = TextFieldDefaults.textFieldColors(
backgroundColor = Color.Transparent
)
)
Run Code Online (Sandbox Code Playgroud) android ×10
textfield ×3
android-jetpack-compose-layout ×1
carousel ×1
image ×1
nine-patch ×1
scroll ×1