小编Tho*_*ohr的帖子

AppCompatButton backgroundTint API <21

我想在Buttons上使用涟漪效果.AppCompat v22.1为AppCompat着色添加了AppCompatButton和新功能.

我的布局:

<android.support.v7.widget.AppCompatButton
        android:id="@+id/add_remove_button"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:backgroundTint="@color/primary"
        android:textColor="@android:color/white"
        android:text="Remove" />
Run Code Online (Sandbox Code Playgroud)

在我的API 22测试设备上,涟漪效应完美无缺,但我正在编写API 11,不幸的是backgroundTint需要API> = 21.如何在旧API版本上将涟漪效果设置为按钮?

android android-appcompat android-button rippledrawable

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

在onCreateViewHolder中获取View的位置

我正在使用带有ImageView和TextView的单行布局的RecyclerView.

我想为View实现一个OnClickListener,而不是为单独的ViewHolder对象实现.如何在适配器中获取视图的位置?

现在我正在删除点击的评论,但我无法选择点击的视图.我在适当的行中添加了一个TODO.

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.ViewHolder> {

    /** List of Comment objects */
    private List<Comment> mCommentList;

    /** Database with Comment objects */
    private CommentsDataSource mDataSource;

    /**
     * Construcutor for CommentAdapter
     *
     * @param commentList   List of Comment objects
     * @param dataSource    Database with Comment objects
     */
    public CommentAdapter(List<Comment> commentList, CommentsDataSource dataSource) {
        this.mCommentList = commentList;
        this.mDataSource = dataSource;
    }

    /**
     * Add Comment objects to RecyclerView
     *
     * @param position  The position where the Comment object is added …
Run Code Online (Sandbox Code Playgroud)

java android android-view android-viewholder android-recyclerview

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