标签: android-components

由于多个构造函数是合适的错误,因此无法选择构造函数

我尝试在我的android kotlin项目中实现持久库,但在编译时捕获此错误:

错误:由于多个构造函数适合,Room无法选择构造函数.尝试使用@Ignore注释不需要的构造函数.

错误代码:

@Entity
data class Site(
        var name: String = "",
        var url: String = "",
        @PrimaryKey(autoGenerate = true) var id: Long = 0)
Run Code Online (Sandbox Code Playgroud)

android constructor kotlin android-components android-room

21
推荐指数
2
解决办法
1万
查看次数

Android导航架构组件 - 导航抽屉图标

我目前正在使用Android架构组件Navigation,但我遇到了问题Navigation Drawer.它在我的起始目的地显示汉堡包菜单,但其他Fragments显示向上箭头.我相信我的设置navigation_graph不正确.

在这里,您可以看到我的导航抽屉,显示2个项目,主页和设置.在其中任何一个片段中,您应该看到汉堡图标.

导航抽屉

但是,在导航到"设置片段"时,它会显示"向上"箭头.

工具栏

navigation.graph.xml

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    app:startDestination="@id/nav_home">

    <!-- Start at HomeFragment -->
    <fragment
        android:id="@+id/nav_home"
        android:name=".HomeFragment"
        android:label="@string/home">

        <!-- Navigate to the Search -->
        <action
            android:id="@+id/action_nav_home_to_nav_search"
            app:destination="@id/nav_search" />
    </fragment>


    <fragment
        android:id="@+id/nav_settings"
        android:name=".SettingsFragment"
        android:label="@string/settings">

        <!-- Navigate to the Search -->
        <action
            android:id="@+id/action_nav_settings_to_nav_search"
            app:destination="@id/nav_search" />
    </fragment>



    <fragment
        android:id="@+id/nav_search"
        android:name=".SearchFragment"
        android:label="@string/search" />

</navigation>
Run Code Online (Sandbox Code Playgroud)

我觉得HomeFragment并且SettingsFragment应该以某种方式相关,但我不确定如何定义它.

main_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="single">
        <item
            android:id="@id/nav_home"
            android:icon="@drawable/ic_home_white_24dp"
            android:title="@string/home" /> …
Run Code Online (Sandbox Code Playgroud)

android navigation-drawer android-components android-jetpack android-architecture-navigation

14
推荐指数
2
解决办法
5620
查看次数

Kotlin android启动新服务

通过使用下面的代码,我试图从启动新服务Broadcast receiver,但该服务未启动。请指导我如何在中启动服务kotlin

val intent = Intent(context, LocationService::class.java)
 if (context != null) {
      context.startService(intent)
 }
Run Code Online (Sandbox Code Playgroud)

android kotlin android-components

9
推荐指数
2
解决办法
7263
查看次数

使用Android的导航组件时在backstack上列出fragments

我正在尝试调试一些代码,并希望在 Android 中列出当前后台堆栈中的片段。库存解决方案是简单地从支持经理中列出它们,因此从活动中方法中:

Log.i("fragments","Count : " + supportFragmentManager.fragments.toString())
Run Code Online (Sandbox Code Playgroud)

但是,将它与 Android 的导航组件一起使用只会列出导航主机片段。

... I/fragments: [NavHostFragment{b1a2d20 (f8ec2420-b534-42df-89f0-0cb189610a26) id=0x7f080001}]
Run Code Online (Sandbox Code Playgroud)

SO 例如Sergii Suvorov 的一些答案提供了以下替代方案:

Log.i("fragments","Count : " + supportFragmentManager.findFragmentById(R.id.NAVIGATION)?.childFragmentManager?.fragments.toString())
Run Code Online (Sandbox Code Playgroud)

这对我来说只是返回 null

... I/fragments: null
Run Code Online (Sandbox Code Playgroud)

片段方法中,我可以调用以下内容

Log.i("fragments", fragmentManager?.fragments.toString())
Run Code Online (Sandbox Code Playgroud)

它确实返回了所需的结果

... I/fragments: [FirstFragment{1475645 (3bb8566b-22b0-4c98-82ea-566e18915145) id=0x7f080001}]
Run Code Online (Sandbox Code Playgroud)

然而,我不知道如何从活动中做到这一点,也许有人知道魔法咒语?

navigation android android-fragments kotlin android-components

8
推荐指数
0
解决办法
1721
查看次数

使用Android房间持久性库在对象内部插入对象

目录

@Entity(tableName = "directory")
class Directory(@PrimaryKey(autoGenerate = false) var id: Int? = null,
                @ColumnInfo(name = DIR_NAME) var dirName: String? = null,
                @Ignore var dirImages: List<Images>? = null

) : Serializable {
    companion object {
        const val DIR_NAME = "dirName"
        const val DIR_IMAGES = "dirImages"
    }
}
Run Code Online (Sandbox Code Playgroud)

影像模型

@Entity(foreignKeys = arrayOf(ForeignKey(entity = Directory::class,
        parentColumns = arrayOf("id"),
        childColumns = arrayOf("id"),
        onDelete = ForeignKey.CASCADE)))

data class Images(
        @PrimaryKey(autoGenerate = false) val id: Int? = null,
        @ColumnInfo(name = "image") val images: String
) { …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-database android-components android-room

7
推荐指数
1
解决办法
2538
查看次数

Android Studio 2.1.1使用选项卡,而不是空格,即使未在"设置"中选中选项卡

编辑Java文件时,如果我在行的末尾并输入Enter键,它会正确地缩短下一行缩进4列,以匹配上面的行.这是确定的,但它与缩进标签,没有空格,即使在File>Settings>Editor>Java>Tabs和缩进的复选框使用制表符取消选中,一直都是.

如果我只是键入tab键,我也会得到一个标签,而不是空格.

我从不想使用制表符; 我总想用空格.我在Eclipse或Microsoft Visual Studio中没有这个问题,因此它不是我的PC的某些系统设置.Android Studio中是否还有其他设置?

编辑: 我尝试了Omar Al Halabi(下面)制作的建议并且它没有工作但是在测试时我发现了一些有趣的东西:这个选项卡问题似乎主要适用于行的开头,即如果我输入Enter在上一行中,它会立即使用实际制表符而非空格切换到下一行的第一个缩进位置.另一方面,如果我在现有行上键入一些文本,一旦我输入了一个小文本,如果我点击了tab,它就会使用空格进行选项卡.

android code-formatting android-studio android-shortcut android-components

6
推荐指数
2
解决办法
585
查看次数

材料设计组件网站

今天我谷歌搜索"材料设计组件"我最终在这个网站:

https://material.io/components/

我记得,我以前从未见过它.

Android部分有指令使用组件和ok,它似乎是着名的Android设计支持库:

依赖关系的屏幕截图

但令我感兴趣的是,那里有组件不在设计库中,例如:

背层布局,材料卡材料按钮.

这些类的文档似乎还没有准备好,链接指向无处,例如:material button doc.

github网站上有一些东西.

抱歉无知,但这个网站的目的是什么?这是未来还是留下的东西?

android material-design android-design-library android-components material-components

6
推荐指数
1
解决办法
1593
查看次数

如何使用导航 UI 组件从片段设置工具栏标题

我有一个带有 Android Studio 中默认布局的工具栏的活动,我可以通过以下方法轻松更改工具栏中的标题:

    Bundle bundle = new Bundle();
    bundle.putString("toolbarTitle", "A new title");

    NavHostFragment
        .findNavController(this)
        .navigate(R.id.action_navigation_conversation_to_placeholder, bundle);
Run Code Online (Sandbox Code Playgroud)

toolbarTitle导航菜单布局中已经实现了安全参数。

但是现在我尝试更改通过上述方法打开的片段的标题,例如;

  • 我的活动->打开->我的片段

  • MyFragment 更改标题

我确实知道如何在不使用导航 UI 组件的情况下更新它,但如果可能的话我想使用它们。

其他类似的问题仅与我上面提供的示例有关,即打开新片段时或建议使用不使用导航 UI 组件的典型方法,没有一个涵盖此特定场景。

android android-titlebar android-navigation android-components

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