相关疑难解决方法(0)

RecyclerView项目中的背景选择器

我正在使用RecyclerView下面的代码:

<android.support.v7.widget.RecyclerView
    android:id="@+id/list"
    android:layout_width="320dp"
    android:layout_height="match_parent"/>
Run Code Online (Sandbox Code Playgroud)

和我的清单项目:

<LinearLayout  android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/selector_medium_high">
    <com.basf.suvinil.crie.ui.common.widget.CircleView
        android:id="@+id/circle"
        android:layout_width="22dp"
        android:layout_height="22dp"/>
    <TextView
        android:id="@+id/label"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="57.5dp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

详细看这部分android:background="@drawable/selector_medium_high"它是一个普通的选择器:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/background_high" android:state_activated="true"/>
    <item android:drawable="@color/background_high" android:state_pressed="true"/>
    <item android:drawable="@color/background_high" android:state_checked="true"/>
    <item android:drawable="@color/background_high" android:state_focused="true"/>
    <item android:drawable="@color/background_medium"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

但是当我运行这段代码时,触摸行时我的背景颜色没有变化....

android selector android-recyclerview

39
推荐指数
6
解决办法
6万
查看次数

"调用需要API级别23"错误,但是来自API 1的FrameLayout上存在getForeground()

摘要

最后,我发现相关问题,setForeground()错误地标记为需要在ViewGroups扩展上使用API​​ 23 FrameLayout.

问题189041:setForeground()被错误地标记为需要扩展FrameLayout的ViewGroups的API 23(NewApi)

如果您没有扩展FrameLayout,那么文档是错误的,并且需要API 23.

问题186273:View.setForeground错误的API级别

更新的问题

被Commonsware 标记为不能setForeground在ImageView上使用方法并由他回答:

这是一个文档错误.setForeground()存在于API Level 1的FrameLayout上; 它仅适用于API级别23的View.

在我的情况下,fork中的检查没有检测到文档错误,但在集成项目中检测到它,我不明白,无论如何,这回答了我的初始问题.

但这不是同一种情况,这个代码已经扩展了Framelayout并且使用了这个方法,它不是一个ImageView,所以我想这个方法已经在API 23中删除了.它现在没有出现在引用中.

更新:我为FrameLayout 添加差异报告:

在此输入图像描述

新问题

所以我的问题改变了如何在以前的版本中使用该方法,为什么有选择地出现检查错误?

如果我添加冗余强制转换,则错误消息将消失:

((FrameLayout) layout).getForeground()
Run Code Online (Sandbox Code Playgroud)

但它正在访问View现在不支持的方法.

因此,我认为针对以前的API会删除错误消息,但我希望使用此Framelayout方法的解决方案或线索来解决我的问题:

ANDROID_COMPILE_SDK_VERSION=23
ANDROID_BUILD_TOOLS_VERSION=23.0.1
ANDROID_DEFAULT_MIN_SDK_VERSION=19
ANDROID_DEFAULT_TARGET_SDK_VERSION=23
Run Code Online (Sandbox Code Playgroud)

解决方法

简而言之,作为一种解决方法,我将类型FrameLayout直接更改为,因此关于API和转换的警告已经消失,我测试它适用于Android 4.4.4设备和调试,我认为它会崩溃,无论如何它只用于一个动画,我将来会修复/更换它.

最初的问题

我分叉和定制的谷歌样品Android的托皮卡,和Android工作室表明,我不理解使用方法所需的API级别的错误getForeground()之类的Viewandroid.view包:

调用需要API级别23(当前最小值为19):android.view.View#getForeground

引用标记了API级别1中添加的方法,而documentation(Control+Q)显示了相同的内容:

Doc显示API级别1方法

但是Calling new methods on older versions inspection显示需要API级别23的错误: …

java android android-studio android-api-levels android-framelayout

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

无法在ImageView上使用setForeground方法

我想使用setForeground方法在我的ImageView中心显示一个"播放"图标,以指示用户按下它时视频将播放.

目前我遇到了这个我无法解决的错误:

在此输入图像描述

虽然文档说自API 1以来该方法应该可用:

在此输入图像描述

我正在使用构建工具版本23.0.1针对API 23进行目标和编译.我的目标是最低API 16.

android imageview

12
推荐指数
2
解决办法
7712
查看次数