小编Євг*_*вич的帖子

Android firebase auth状态监听器多次调用

我正在使用Firebase android sdk v.9.0.2,现在无法通过注册.我正在添加一个身份验证状态监听器并在成功注册时将其删除.然而它被称为多次.这就是我在日志中得到的:

D/FirebaseAuth: Notifying listeners about a sign-out event.
D/FirebaseApp: Notifying auth state listeners.
D/FirebaseApp: Notified 0 auth state listeners.
D/ActivityRegister: auth listener called
D/FirebaseAuth: Notifying listeners about user ( bwVX8jBbZvYcIj28hYsGZCcbzxi1 ).
D/FirebaseApp: Notifying auth state listeners.
D/FirebaseApp: Notified 0 auth state listeners.
D/ActivityRegister: auth listener called
D/FirebaseAuth: Notifying listeners about user ( bwVX8jBbZvYcIj28hYsGZCcbzxi1 ).
D/FirebaseApp: Notifying auth state listeners.
D/FirebaseApp: Notified 1 auth state listeners.
Run Code Online (Sandbox Code Playgroud)

"D/ActivityRegister:auth listener called"日志位于监听器iteself中.正如您所看到的,当Firebase通知0个侦听器时,实际上会调用它.当它显示1个监听器时,监听器根本不会被调用.这有什么解决方法吗?

android firebase firebase-authentication

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

缺少ConstraintLayout属性选项卡

我决定尝试新的ContraintLayout,但properties标签丢失了.

我使用的是AndroidStudio 2.3,ConstraintLayout 1.0.2.

有没有办法打开它?

android android-constraintlayout

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

Androidx滚动视图行为不起作用

切换到androidx后,以下代码停止工作。工具栏下面的TextView用于滚动内容,但现在不滚动。我设法使它只有在将相同的scrollFlags设置为Toolbar时才起作用,但我想保留它。除了将工具栏移出AppBarLayout和CoordinatorLayout之外,还有其他解决方案吗?

<androidx.coordinatorlayout.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <androidx.appcompat.widget.Toolbar
                app:title="Non-scrollable title"
                android:layout_width="wrap_content"
                android:layout_height="?android:attr/actionBarSize"/>

        <TextView
                app:layout_scrollFlags="scroll"
                android:layout_margin="16dp"
                android:textSize="20sp"
                android:text="this should scroll with the content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <!-- some scrollable content here -->

    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android-appbarlayout androidx

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

Android TV将焦点转移到RecyclerViews之间

我正在使用以下布局构建Android TV应用: 在此输入图像描述

左侧和右侧的两个列表都是带有垂直LinearLayoutManagers的RecyclerViews,Header视图是静态的.使用D-PAD导航在一个列表中工作正常,但是当从一个列表切换到另一个列表时,存在问题.焦点从list1的项目5移动到list2'项目5.当列表2短的时间少于5项时,它就会失去焦点.

我希望保存最后一个聚焦项目索引,并且当用户导航list1-list2-list1时,具有该索引的项目再次获得焦点并且还防止视图失去焦点.这有什么好的解决方案吗?

所需行为:用户导航到列表顶部并按"向上" - 焦点保持原样,没有任何反应.用户导航到列表的底部并按下"向下" - 焦点停留在原来的位置,没有任何反应.用户从list1导航到list2 - 之前在list2中具有焦点的项目,如果之前没有聚焦,则获得焦点或item0获得焦点.

主要布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <ImageView
        android:id="@+id/iv_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="false"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="27dp"
        android:layout_marginLeft="48dp"
        android:layout_marginRight="48dp"
        android:layout_marginTop="27dp"
        android:orientation="horizontal"
        >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:orientation="vertical"
            >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:orientation="horizontal"
                >

                <ImageView
                    android:id="@+id/iv_poster"
                    android:layout_width="@dimen/episodes_list_item_height"
                    android:layout_height="@dimen/episodes_list_image_width"
                    />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    >

                    <TextView
                        android:id="@+id/tv_title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        />

                    <FrameLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        >

                        <TextView
                            android:id="@+id/tv_release_date"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="left"
                            />

                        <TextView
                            android:id="@+id/tv_rating"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="right"
                            android:drawableLeft="@drawable/ic_star_white_24dp" …
Run Code Online (Sandbox Code Playgroud)

focus d-pad android-tv android-recyclerview

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

立即调用 workmanager 侦听器

我需要在 WorkManager (android.arch.work:work-runtime-ktx:1.0.0-alpha11) 完成工作时进行回调。然而,我正在添加的侦听器在安排工作后立即被调用。

这是我所做的:

val work = OneTimeWorkRequestBuilder<UploadWorker>()
                .setConstraints(constraints)
                .setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 1, TimeUnit.MINUTES)
                .setInputData(inputData)
                .build()
workManager.beginUniqueWork(INSURANCE_UPLOAD_WORKER, ExistingWorkPolicy.REPLACE, work)
                .enqueue().result.toWorkResult()
Run Code Online (Sandbox Code Playgroud)

UploadWorker 类只有在完成整个上传序列后才返回 Success。

这是扩展功能代码:

private val executor = Executor { command -> command?.run() }

class WorkResult(private val future: ListenableFuture<*>) {

    fun addListener(listener: () -> Unit) {
        future.addListener(Runnable {
            debugLog("work result listener runnable called")
            listener()
        }, executor)
    }

}

internal fun ListenableFuture<*>.toWorkResult(): WorkResult {
    return WorkResult(this)
}
Run Code Online (Sandbox Code Playgroud)

当我将侦听器添加到 WorkResult 时,它们都会立即被调用,而无需等待实际工作完成。对此有什么想法吗?

android android-workmanager

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

Android NavigationView项目涟漪效应

我想在单击项目时在android.support.design.widget.NavigationView中实现涟漪效果.我已经在我的主题中定义了波纹颜色.长按NavigationView的菜单项时,我可以看到正确的涟漪效果.但是当它是一个短暂的点击时,没有任何反应 - 没有波纹,没有任何点击的迹象.

我已经尝试为NavigationDrawer设置app:itemBackground ="?attr/selectableItemBackground".它不会改变任何东西,抽屉的行为就像插入这条线之前一样.

请帮助我在API 16+上获得连锁反应.谢谢.

android ripple navigationview android-navigationview

5
推荐指数
0
解决办法
844
查看次数

以编程方式将TextView的文本样式设置为TextAppearance.Appcompat

我一直在使用:

    style="@style/TextAppearance.AppCompat.SearchResult.Title"
Run Code Online (Sandbox Code Playgroud)

在我的布局xml中,但这次我想以编程方式从java代码设置文本样式.但是这段代码:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        textView.setTextAppearance(R.style.TextAppearance.AppCompat.SearchResult.Title);
    } else {
        textView.setTextAppearance(this, R.style.TextAppearance.AppCompat.SearchResult.Title);
    }
Run Code Online (Sandbox Code Playgroud)

不编译.它说'无法解析符号'TextAppearance'.

android text-styling

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

Android工具栏菜单文字颜色

我试图在这里更改我的工具栏的菜单项文本颜色,但它不起作用.这是我的风格:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="toolbarStyle">@style/AppTheme.ToolbarStyle</item>
    <item name="buttonStyle">@style/AppTheme.ButtonStyle</item>
    <item name="colorControlHighlight">@color/colorPrimary</item>
</style>
<style name="AppTheme.ToolbarStyle" parent="Base.Theme.AppCompat.Light.DarkActionBar">
    <item name="android:background">@color/colorPrimary</item>
    <item name="titleTextColor">@android:color/white</item>
    <item name="titleTextAppearance">@style/TextAppearance.AppCompat.Widget.ActionBar.Title
    </item>
    <item name="actionMenuTextColor">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)

layout xml:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:title="@string/app_name"
    app:titleMarginStart="@dimen/margin_l"
    />
Run Code Online (Sandbox Code Playgroud)

我试图直接在xml中设置工具栏主题,但菜单项仍然回来了.这个问题有方法解决吗?

在此输入图像描述

android toolbar android-toolbar

5
推荐指数
4
解决办法
3835
查看次数

Android Gradle在另一个模块中包含模块依赖项

我正在使用最新的Android Studio 3.0.0-beta6来构建我的Android项目,并且存在此依赖项问题。 Gradle鼓励我compile'simplementation's。这是我的项目结构:

项目:

  • 模块1

    • 模块2

Module1取决于某些库,module2取决于module1。但是,来自module1的库在module2中不可见。我不想复制粘贴依赖项,而是只将库依赖项声明一次。有一个简单的解决方案吗?谢谢。

module1的构建包:

dependencies {
    ....
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    ...
}
Run Code Online (Sandbox Code Playgroud)

module2的构建包:

implementation project(':module1')
Run Code Online (Sandbox Code Playgroud)

dependencies android android-gradle-plugin

5
推荐指数
2
解决办法
2080
查看次数

无法解析符号“偏好”

我正在构建一个 Android TV 应用程序并想使用

LeanbackListPreferenceDialogFragment
Run Code Online (Sandbox Code Playgroud)

但是,工作室在我的导入字符串上显示“无法解析符号“首选项”:

import android.support.v17.preference.LeanbackListPreferenceDialogFragment;
Run Code Online (Sandbox Code Playgroud)

我在 build.gradle 中添加了 Leanback 库依赖项:

compile 'com.android.support:leanback-v17:25.0.0'
Run Code Online (Sandbox Code Playgroud)

API 参考链接:https : //developer.android.com/reference/android/support/v17/preference/LeanbackListPreferenceDialogFragment.html

任何提示和帮助表示赞赏。

尤金

android android-tv leanback

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