小编Pop*_*tar的帖子

如何在屏幕旋转或系统主题更改后将光标移动到 TextField 的末尾并保持键盘显示?

我有一个带有Textfield搜索栏的屏幕,当屏幕首次显示时,它会自动对焦。问题是,在screen rotationor system theme change(深色模式/浅色模式)之后,cursor即使 TextField 的值不为空并且键盘自行消失,也会在 TextField 的开头移动。请帮忙,我已经找了两天了。一些代码示例:

撰写版本:1.3.0 材料 3:1.0.0

SearchBookScreen.kt

val myViewModel = SearchBookViewModel()

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SearchBookScreen(
    modifier: Modifier = Modifier,
    navController: NavController,
    viewModel: SearchBookViewModel = myViewModel,
    filters: Map<SearchFilterType, FilterOptions> = FILTERS
) {
    val focusRequester = remember { FocusRequester() } 

val searchInputValue = viewModel.searchInputValue.value
val filtersState = viewModel.filtersState

LaunchedEffect(Unit) { this.coroutineContext.job.invokeOnCompletion { focusRequester.requestFocus() } }

Scaffold(
    topBar = {
        Column {
            TextField(
                singleLine = true,
                placeholder = { …
Run Code Online (Sandbox Code Playgroud)

keyboard android focus android-jetpack-compose material3

5
推荐指数
1
解决办法
645
查看次数

如何解决 Angular 10 primeng NullInjectorError: No provider for ConfirmationService?

我正在使用primeng confirmDialog,它在我的Angular 10项目中需要confirmationService,但localhost:4200没有显示任何内容,我在Chrome控制台中收到以下错误。

ERROR NullInjectorError: R3InjectorError(AppModule)[ConfirmationService -> ConfirmationService -> ConfirmationService]: 
NullInjectorError: No provider for ConfirmationService!
  at NullInjector.get (http://localhost:4200/vendor.js:27059:27)
  at R3Injector.get (http://localhost:4200/vendor.js:37225:33)
  at R3Injector.get (http://localhost:4200/vendor.js:37225:33)
  at R3Injector.get (http://localhost:4200/vendor.js:37225:33)
  at NgModuleRef$1.get (http://localhost:4200/vendor.js:50342:33)
  at Object.get (http://localhost:4200/vendor.js:48245:35)
  at getOrCreateInjectable (http://localhost:4200/vendor.js:30065:39)
  at Module.??directiveInject (http://localhost:4200/vendor.js:39896:12)
  at NodeInjectorFactory.AppComponent_Factory [as factory] (http://localhost:4200/main.js:158:150)
  at getNodeInjectable (http://localhost:4200/vendor.js:30173:44)
Run Code Online (Sandbox Code Playgroud)

这是我的 app.component.ts。

import { Component } from '@angular/core';
import { ConfirmationService } from 'primeng/api';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']

})
export class AppComponent {
  title = 'angular-tuts';

  constructor(private confirmationService: ConfirmationService) { …
Run Code Online (Sandbox Code Playgroud)

primeng angular primeng-dialog

3
推荐指数
1
解决办法
3289
查看次数