TextField(
value = productViewModel.zhCode,
onValueChange = { productViewModel.zhCode = it },
modifier = Modifier
.weight(1f)
.border(1.dp, Color.Gray, RoundedCornerShape(4.dp))
.padding(4.dp),
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done // 设置回车动作为“完成”
),
keyboardActions = KeyboardActions(
onDone = {
// 执行回车动作时的操作
keyboardController?.hide() // 隐藏键盘
productViewModel.zhEnter() // 触发回调函数
}
),
)
1
ssccyy OP 手持 PDA 设备:iData 95S
手持 PDA 设备系统: 安卓 6.0 项目 build.gradle plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'org.jetbrains.kotlin.plugin.parcelize' } android { compileSdk 34 defaultConfig { applicationId "icu.bughub.app.app" minSdk 21 targetSdk 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary true } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } buildFeatures { compose true } composeOptions { kotlinCompilerExtensionVersion compose_version } packagingOptions { resources { excludes += '/META-INF/{AL2.0,LGPL2.1}' } pickFirst '**/libc++_shared.so' doNotStrip "*/arm64-v8a/libYTCommon.so" } } dependencies { implementation 'androidx.core:core-ktx:1.7.0' implementation "androidx.compose.ui:ui:$compose_version" implementation "androidx.compose.material:material:$compose_version" implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" def lifecycle_version = "2.4.1" implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version" implementation 'androidx.activity:activity-compose:1.4.0' //accompanist def accompanist_version = "0.24.3-alpha" implementation "com.google.accompanist:accompanist-systemuicontroller:$accompanist_version" implementation "com.google.accompanist:accompanist-insets:$accompanist_version" implementation "com.google.accompanist:accompanist-pager:$accompanist_version" implementation "com.google.accompanist:accompanist-navigation-animation:$accompanist_version" implementation "com.google.accompanist:accompanist-placeholder-material:$accompanist_version" implementation "com.google.accompanist:accompanist-swiperefresh:$accompanist_version" //图标扩展 implementation "androidx.compose.material:material-icons-extended:$compose_version" implementation "androidx.constraintlayout:constraintlayout-compose:1.0.0" //图片加载 implementation("io.coil-kt:coil-compose:2.0.0-rc01") //webview implementation project(path: ':webview') //播放器 implementation 'com.tencent.liteav:LiteAVSDK_Player:latest.release' //datastore implementation "androidx.datastore:datastore-preferences:1.0.0" def retrofit = "2.9.0" //网络请求框架 implementation "com.squareup.retrofit2:retrofit:$retrofit" //GSON // implementation "com.squareup.retrofit2:converter-gson:$retrofit" //moshi implementation "com.squareup.retrofit2:converter-moshi:$retrofit" def moshi_version = "1.13.0" implementation "com.squareup.moshi:moshi-kotlin:$moshi_version" testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" } 会不会是我需要开什么原型的权限或者是什么行为。 |
2
nicevar 202 天前
不要什么权限,直接监听按键事件处理,google 的 compose 没几个人愿意用,问题都没几个人回答了。
|
3
lxiian 202 天前
pda 设备回车就是往 edittext 里发送了个“\n”的换行符,直接监听这个就行了吧,不需要自带的 ImeAction 去判断
|
5
ssccyy OP @lxiian 感谢有空研究下监听 \n, 目前的解决方案是在 modifier 上判断的回车事件
modifier = Modifier .weight(1f) .border(1.dp, Color.Gray, RoundedCornerShape(4.dp)) .padding(4.dp) .onKeyEvent { // if (it.key.keyCode == Key.Backspace.keyCode) { // it.key.keyCode if (it.key.keyCode == Key.Enter.keyCode) { productViewModel.zhEnter() // 触发回调函数 } false } |