kotlin 相关问题

Kotlin是一种由JetBrains支持的开源,静态类型编程语言。 Kotlin结合了OO和功能特性,专注于互操作性,安全性,清晰度和工具支持。它目前面向JVM和JavaScript,它是Android上官方支持的语言。

如何为 micronaut 中的所有控制器设置基本 url?通过 application.yml 或任何配置

如何设置所有控制器的基本URL @Controller(“/api/你好”) 类HelloController{ @Get("/问候") 有趣的问候(){ } } 有一种方法可以代替在每个控制器上编写/api...

回答 3 投票 0

使用序列化使用循环引用和自定义 getter 深度复制复杂对象

我编写了一个复杂的 Kotlin 类 Env,其中需要实现一个 deepCopy 方法。这是该类及其引用类的最小复制示例: @可序列化 类环境( 过度...

回答 1 投票 0

Gradle 依赖使用说明:Kotlin 多平台

今天我尝试更深入地了解 Gradle 和依赖项(Kotlin)。 但是,我现在对依赖关系有点困惑。 我想将 Ktor 客户端包含在一个项目中以供练习......

回答 1 投票 0

如何使用 Android Profiler 识别 Android 应用程序中的哪些代码启动线程的创建

我正在开发一个基于插件的应用程序,它有不同的插件。每个插件都是独立于其他插件的。我还使用 Google Places API 作为其中的插件。有一个选项可以引用...

回答 1 投票 0

列表中每个项目的 Kotlin 基本数学

我不太了解如何在 Kotlin 中正确使用列表,即使是简单的事情。 假设我有一个双打列表,并且我想要一个两倍大的列表。所以对于 [1.0, 2.0, 3.0] 我想要 [2...

回答 2 投票 0

如何使小部件在 Jetpack Compose 中不可见?

我正在尝试在列中显示和隐藏 ProgressIndicator。 问题是当我想隐藏 ProgressIndicator 时,其他小部件之间的空间也会被删除(如 View.GONE),但我想

回答 6 投票 0

如何将aar库导入到flutter插件中?

我正在尝试将库导入到flutter插件中,但设置非常奇怪,因为你有 android 文件夹和examples/android 文件夹。基本上我只需要能够访问li...

回答 1 投票 0

Kotlin:多行字符串中的行继续?

val myQuestion = """ 我正在创建一个包含文本段落的多行字符串。 当放入 TextView 时,文本将换行。 但正如您所看到的,在

回答 2 投票 0

流式传输两个集合并根据公共属性收集地图

我环顾四周,但没有找到一个优雅的解决方案。我想做的是有一个很好的简化(双关语)解决方案,从两个拥有 1 个共享项目的集合创建一个地图...

回答 1 投票 0

显式支持字段在最新的 kotlin 2.0.0 android 中不起作用

我正在使用 Kotlin 2.0.0。我正在我当前的 android 项目中尝试。我正在从这个视频中尝试。 类 MainActivity : ComponentActivity() { 验证状态:StateFlow 场 =

回答 1 投票 0

无版本的插件依赖项(迁移版本目录)

我开始迁移我的项目以使用新版本目录,没有版本的插件会给出错误,指出需要该版本。 我如何将下面的插件添加到 toml 文件中,因为我...

回答 1 投票 0

如何防止 CircularProgressIndicator 在 Kotlin Compose 身份验证过程中冻结?

我有一个 Kotlin Compose 应用程序,允许用户通过 Facebook 和 Google 进行身份验证。在登录过程中,会显示一个 CircularProgressIndicator 并旋转,直到用户的帐户创建...

回答 1 投票 0

从购物车中删除商品会导致应用程序崩溃,但仍会删除该商品

已开发购物车窗口。数据被写入数据库。当您单击删除图标时,产品将从数据库和用户窗口中删除,但应用程序

回答 1 投票 0

使用最新的 Sentry 依赖项时,类的执行数据在 Jacoco 中不匹配

添加最新的 Sentry 依赖项(7.6.0)后,我的测试覆盖范围被破坏。我的一些课程开始收到这些错误: [ant:jacocoReport] 包“app”中的类与

回答 1 投票 0

卸载应用程序后,SharedPreferences 值不会被清除

问题是特定于设备的或我不知道的,但是,我运行应用程序,然后卸载应用程序,然后再次运行应用程序,但 SharedPreferences 值仍然存在。我用的是小米11TPro。我确实...

回答 1 投票 0

为什么使用AndroidX时嵌套的PreferenceScreen打不开?

我正在使用 AndroidX 的首选项库来管理我的应用程序的设置。我的 SettingsFragment 派生自 PreferenceFragmentCompat 并加载以下布局: 我正在使用 AndroidX 的首选项库来管理我的应用程序的设置。我的 SettingsFragment 源自 PreferenceFragmentCompat 并加载以下布局: <androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <androidx.preference.PreferenceScreen android:key="screen_backup_key" android:title="@string/local_database"> <androidx.preference.Preference android:key="button_save_key" android:title="@string/export" /> <androidx.preference.Preference android:key="button_load_key" android:title="@string/_import" /> </androidx.preference.PreferenceScreen> <androidx.preference.Preference android:key="screen_about" android:title="@string/about" /> </androidx.preference.PreferenceScreen> 布局显示正确,但是当我单击嵌套的 PreferenceScreen 条目时,没有任何反应。它以前可以与 支持库 中的 PreferenceScreen 一起使用,但现已弃用。 我希望看到这个嵌套的内容PreferenceScreen。我做错了什么? AndroidX 的首选项库不再支持它。 使用 a 声明同一 XML 资源中的嵌套层次结构 不再支持嵌套 PreferenceScreen。你应该使用 而是嵌套的 Fragment 对象。 每个单独的屏幕都需要一个单独的 PreferenceFragmentCompat。 如果您有大量偏好或不同类别,您 可以将它们显示在单独的屏幕上。每个屏幕应该是一个 PreferenceFragmentCompat 有自己独立的层次结构。优先 然后,您的初始屏幕上可以链接到包含以下内容的子屏幕: 相关首选项。 你这样做: 要将屏幕与首选项链接,您可以在中声明 app:fragment XML,或者您可以使用 Preference.setFragment()。设置完整包 启动时应启动的 PreferenceFragmentCompat 的名称 点击Preference,如下图: <Preference app:fragment="com.example.SyncFragment" .../> 这是进一步阅读的来源。 嵌套 ScreenPreference 无法在 AndroidX 中开箱即用。下面是一个处理嵌套 ScreenPreference 的 PreferenceActivity 替换示例。类似的方法可以仅用于片段。 注意以下事项: 活动布局没有利用大屏幕或可折叠设备。 片段不会持续存在(因此,如果屏幕旋转,它将返回到第一个首选项片段)。 只能调用一次addPreferencesFromResource()。 以下是如何使用它来替换 PreferenceActivity 作为基类: 将 PreferenceActivity 替换为 PreferenceActivityEx。 将 AppCompatActivity 兼容主题添加到 AndroidManifest.xml 中的继承 Activity。例如:android:theme="@style/Theme.AppCompat"。 将任何 androidx.preference 导入替换为 androidx.preference。 将 addPreferencesFromResource() 方法中的 onCreate() 调用之后处理首选项的代码移至新的覆盖 onPreferencesCreated() 方法。 activity_preference_ex.xml: <?xml version="1.0" encoding="utf-8"?> <androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/preferences_container" android:layout_width="match_parent" android:layout_height="match_parent" /> PreferenceActivityEx.java: import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceScreen; public class PreferenceActivityEx extends AppCompatActivity { private RootPreferenceFragmentCompatEx mPreferencesFragment; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_preference_ex); } @Override protected void onResume() { super.onResume(); if (mPreferencesFragment == null) throw new IllegalStateException("Must call 'addPreferencesFromResource()' in the 'onCreate()' method."); } protected Preference findPreference(@NonNull CharSequence key) { if (mPreferencesFragment == null) throw new IllegalStateException("Must call 'addPreferencesFromResource()' before 'findPreference()'"); return mPreferencesFragment.findPreference(key); } protected PreferenceScreen getPreferenceScreen() { if (mPreferencesFragment == null) throw new IllegalStateException("Must call 'addPreferencesFromResource()' before 'getPreferenceScreen()'"); return mPreferencesFragment.getPreferenceScreen(); } protected void onPreferencesCreated() { } protected void addPreferencesFromResource(int preferencesResId) { if (mPreferencesFragment != null) throw new IllegalStateException("Only a single call to addPreferencesFromResource() is allowed."); mPreferencesFragment = new RootPreferenceFragmentCompatEx(preferencesResId); mPreferencesFragment.setOnPreferencesCreatedListener(this::onPreferencesCreated); getSupportFragmentManager().beginTransaction() .replace(R.id.preferences_container, mPreferencesFragment) .commit(); } public static abstract class PreferenceFragmentCompatEx extends PreferenceFragmentCompat { @Override public boolean onPreferenceTreeClick(@NonNull Preference preference) { if (preference instanceof PreferenceScreen) { PreferenceScreen preferenceScreen = (PreferenceScreen) preference; // Create a new fragment to display the nested PreferenceScreen NodePreferenceFragmentCompatEx fragment = new NodePreferenceFragmentCompatEx(preferenceScreen); // Use the FragmentManager to replace the current fragment with the nested one getParentFragmentManager().beginTransaction() .replace(getId(), fragment) .addToBackStack(null) .commit(); return true; } return super.onPreferenceTreeClick(preference); } } public static class NodePreferenceFragmentCompatEx extends PreferenceFragmentCompatEx { private PreferenceScreen mPreferenceScreen; public NodePreferenceFragmentCompatEx() { } public NodePreferenceFragmentCompatEx(PreferenceScreen preferenceScreen) { mPreferenceScreen = preferenceScreen; } @Override public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { if (mPreferenceScreen != null) setPreferenceScreen(mPreferenceScreen); } } public static class RootPreferenceFragmentCompatEx extends PreferenceFragmentCompatEx { private int mPreferencesResId; private OnPreferencesCreatedListener mOnPreferencesCreatedListener; public RootPreferenceFragmentCompatEx() { } public RootPreferenceFragmentCompatEx(int preferencesResId) { mPreferencesResId = preferencesResId; } private void setOnPreferencesCreatedListener(OnPreferencesCreatedListener onPreferencesCreatedListener) { mOnPreferencesCreatedListener = onPreferencesCreatedListener; } @Override public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { if (mPreferencesResId != 0) { setPreferencesFromResource(mPreferencesResId, rootKey); if (mOnPreferencesCreatedListener != null) mOnPreferencesCreatedListener.onPreferencesCreated(); } } } private interface OnPreferencesCreatedListener { void onPreferencesCreated(); } }

回答 2 投票 0

从购物车中删除商品时应用程序崩溃

在移动应用程序中,我创建了一个从垃圾箱中删除的功能,为此我创建了一个单独的 CartAdapter 并在其中输入了以下代码: 类 CartAdapter( 私人 val 上下文:Co...

回答 1 投票 0

Flutter:模块是使用不兼容的 Kotlin 版本编译的。其元数据的二进制版本是1.9.0,预期版本是1.7.1

每当我第一次运行“flutter buid apk”时,我都会收到这些错误。第一次之后,如果我再次构建,它就不会发生。如果我清除缓存并再次构建,那么它会再次发生......

回答 2 投票 0

Kotlin 多平台库未生成 iosSimulatorArm64Main、iosArm64Main、iosX64Main 和测试目标

我正在创建一个 kotlin 多平台库,该库在 commonMain 中只有 kotlin 代码,在 iOS main 和 androidMain 中没有任何内容, 并使用 GithubPackages 来分发它,使用命令行 ./gra...

回答 1 投票 0

原始字符串中的换行符是否与平台相关?

原始字符串中的换行符是否与平台相关? val a = "一 二”; val b = """一 二””” println(a==b) 换句话说,上面的 println 语句是否保证打印 true 或 not?

回答 3 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.