英文:
How to capitalize letters in custom keyboard in Jatpack Compose?
问题
以下是您要翻译的内容:
"I've been trying to figure out how to capitalize letters in my custom IME keyboard. I created capitalize key but I don't know what I have to put into
clickable(interactionSource = interactionSource, indication = null)
Maybe someone knows more how works with keyboard in Compose. Do you guys know how to achieve this in Jetpack Compose?"
英文:
I've been trying to figure out how to capitalize letters in my custom IME keyboard. I created capitalize key but I don't know what I have to put into
clickable(interactionSource = interactionSource, indication = null)
Maybe someone knows more how works with keyboard in Compose. Do you guys know how to achieve this in Jetpack Compose?
@Composable
fun KeyboardKeyCaps(
keyboardKey: String, viewKeyboard: KeyboardViewModel
) {
val interactionSource = remember { MutableInteractionSource() }
val pressed = interactionSource.collectIsPressedAsState()
val context = LocalContext.current
val viewmodel = viewKeyboard
val color by viewmodel.colorKeys.collectAsState()
Box(contentAlignment = Alignment.Center) {
Text(keyboardKey,
Modifier
.background(Color(android.graphics.Color.parseColor("#" + color)))
.border(3.dp, Color.Black)
.clickable(interactionSource = interactionSource, indication = null) {
(context as IMEService).currentInputConnection.let {
}
}
.padding(
start = 12.dp, end = 12.dp, top = 16.dp, bottom = 16.dp
)
)
if (pressed.value) {
Text(
keyboardKey,
Modifier
.border(1.dp, Color.Black)
.background(Color.Gray)
.padding(
start = 13.dp, end = 13.dp, top = 17.dp, bottom = 17.dp
)
)
}
}
}
Usual Key
@Composable
fun KeyboardKey(
keyboardKey: String, viewKeyboard: KeyboardViewModel
) {
val interactionSource = remember { MutableInteractionSource() }
val pressed = interactionSource.collectIsPressedAsState()
val context = LocalContext.current
val viewmodel = viewKeyboard
val color by viewmodel.colorKeys.collectAsState()
Box(contentAlignment = Alignment.Center) {
Text(keyboardKey,
Modifier
.background(Color(android.graphics.Color.parseColor("#" + color)))
.border(3.dp, Color.Black)
.clickable(interactionSource = interactionSource, indication = null) {
(context as IMEService).currentInputConnection.commitText(
keyboardKey, 0
)
}
.padding(
start = 12.dp, end = 12.dp, top = 16.dp, bottom = 16.dp
)
)
if (pressed.value) {
Text(
keyboardKey,
Modifier.graphicsLayer(clip = false)
.border(1.dp, Color.Black)
.background(Color.Gray)
.padding(
start = 16.dp, end = 16.dp, top = 36.dp, bottom = 16.dp
)
)
}
}
}
Screenshots
答案1
得分: 0
https://github.com/IBRUTALI/KeyboardApp
这是如何在Compose中将按键大写的最佳示例。
英文:
https://github.com/IBRUTALI/KeyboardApp
There is the best example How to capitalize key in compose.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论