相关疑难解决方法(0)

如何以编程方式将selectableItemBackground添加到ImageButton?

android.R.attr.selectableItemBackground存在,但是如何以编程方式将其添加到ImageButton?

另外,我将如何在文档中找到答案?这里提到,但我没有看到它是如何实际使用的任何解释.实际上,我似乎很少发现文档有用,但我希望这是我的错,而不是文档的错.

android attr r.java-file

49
推荐指数
3
解决办法
3万
查看次数

RecyclerView + CardView +触摸反馈

当有人在RecyclerView内部时,有没有人解决了CardView之谜而没有触摸反馈?

我有一个带有一堆CardViews(一个CardList)的RecyclerView.当我点击任何CardView时,我启动另一个Activity.这工作得很好,但是当我点击CardView时,我看不到任何触摸反馈.

及时,我已经使用以下方法配置了我的CardView(XML):

android:clickable="true"
android:background="?android:selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)

谢谢!

android touch android-cardview android-5.0-lollipop android-recyclerview

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

将 selectableItemBackground 添​​加到 CardView

我想将CardView的前景设置为?attr/selectableItemBackground.

当我在 xml 中声明前景时它起作用:

android:foreground="?attr/selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)

但我想以编程方式设置前景。这不起作用:

int[] attrs = new int[]{R.attr.color_a, R.attr.selectableItemBackground};
TypedArray ta = context.obtainStyledAttributes(attrs);
mColorA = ta.getColor(0, 0);
mSelectableItemBackground = ContextCompat.getDrawable(context, ta.getResourceId(1, 0));
ta.recycle();

...

cardView.setOnClickListener(onClickListener);
cardView.setClickable(true);
cardView.setForeground(mSelectableItemBackground);
Run Code Online (Sandbox Code Playgroud)

但是,检索属性有效(mSelectableItemBackground 包含一个RippleDrawable),但是当我按下卡片时前景不会改变。

android android-xml android-cardview

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

androidx.cardview.widget.CardView 上的波纹效果

我正试图在点击卡片视图时添加涟漪效果,奇怪的是它没有出现?

这里可能有什么问题?

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/tools"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:foreground="?android:attr/selectableItemBackground"
    android:clickable="true"
    android:layout_margin="5dp"
    card_view:cardCornerRadius="6dp"
    card_view:contentPadding="5dp"
    card_view:cardElevation="4dp"
    card_view:cardMaxElevation="6dp"
    app:ignore="NamespaceTypo"> 


</androidx.cardview.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

// 我在cardview中有一个带有三个textview的线性布局。

回收者视图:

<LinearLayout
        android:id="@+id/cardViewLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:visibility="gone">

        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swipe_refresh_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/cardList"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

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

谢谢!

android android-cardview

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