在RecyclerView中禁用搜索栏

时间:2018-06-19 11:50:59

标签: android android-seekbar

我需要在RecyclerView中播放音频。要求是SeekBar将在用户单击播放按钮后启用。所以我尝试了。

<SeekBar
                android:id="@+id/seek_Media_Player"
                android:layout_width="match_parent"
                android:layout_marginLeft="@dimen/_6sdp"
                android:clickable="false"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:layout_marginRight="@dimen/_6sdp"
                android:layout_height="wrap_content" />

但是它不起作用。当我在android:clickable="false"SeekBar内而不是Activity内使用Fragment时,RecyclerView起作用了。我也尝试在运行时设置那些属性,但是没有用。

设置setEnabled(false)以使SeekBar不可见。最近6个小时以来,我一直在脑筋急转弯。我发布项目图片只是为了显示。请让我知道如何禁用/启用点击SeekBar

enter image description here

1 个答案:

答案 0 :(得分:0)

好的,所以我找到了解决方案。以前有人怀疑过,但我在寻找其他方法来做。我认为问题出在我的代码中。但事实并非如此。以下是我使用过的完整解决方案。

public class CustomSeekBar extends AppCompatSeekBar {
private boolean fuzzyEnable;

public void setFuzzyEnable(boolean fuzzyEnable) {
    this.fuzzyEnable = fuzzyEnable;
}
public CustomSeekBar(Context context) {
    super(context);
}

public CustomSeekBar(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    return fuzzyEnable?super.onTouchEvent(event):true;
}

}