我有一个像这样的字符串资源
<string name="my_string">Fancy string with an %1$s placeholder</string>
Run Code Online (Sandbox Code Playgroud)
我希望将其作为输出:“带有令人惊叹的占位符的精美字符串”。这是占位符内容以粗体显示的字符串。
我怎样才能得到想要的输出?
当文本字段获得焦点时,如何将光标设置在其随机位置?相当于editText.setSelection(position)经典的 android 视图系统。
这是我用来让编辑文本在添加到屏幕时自动接收焦点的代码。我希望能够将光标从默认位置 0 移开
val (getText, setText) = remember { mutableStateOf("hello") }
AutofocusEditText(
text = getText,
setText = setText
)
...
@Composable
private fun AutofocusEditText(
text: String,
setText : (String) -> Unit
) {
val focusState = remember { mutableStateOf(FocusState.Inactive) }
val focusRequester = FocusRequester()
val focusModifier = Modifier.focus()
Row(
modifier = Modifier.focusObserver { newFocusValue -> focusState.value = newFocusValue }
) {
val focusRequesterModifier =
Modifier.focusRequester(focusRequester)
TextField(
value = text,
modifier = focusModifier.then(focusRequesterModifier),
backgroundColor = Color.Transparent, …Run Code Online (Sandbox Code Playgroud) 在Android 5.0.2上更新supportVersion到27.0.0ONLY后,应用程序崩溃了这个堆栈跟踪:
W/WindowManager: Failed looking up window
java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W@f004691 does not exist
at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8426)
at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8417)
at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2558)
at com.android.server.wm.Session.remove(Session.java:186)
at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:2920)
at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5390)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3223)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
Run Code Online (Sandbox Code Playgroud)
无论是在设备上还是在模拟器上.
如果我把26.0.2作为supportVersion,应用程序仍然像往常一样正常工作.
UPDATE
问题依然存在 supportVersion 27.0.1
更新2
项目gradle
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'io.fabric.tools:gradle:1.24.2'
}
}
plugins {
id "com.diffplug.gradle.spotless" version …Run Code Online (Sandbox Code Playgroud)