如何在GridLayout中将设置图像按钮背景设置为透明

How to set set image button background to transparent in GridLayout

这与我之前发布的两个问题不同,应用相同但问题不同。 我正在使用 RecyclerView 一次一个地向 GridLayout 添加 ImageButtons。我的应用侦听传入的图像和字符串来标记按钮。

我需要按钮的背景是透明的(不是你看到的灰色方块)。如果我设置:

android:background="#00000000"

对于使用 RecyclerView 填充的空白图像按钮,它就像一个透明按钮放置在我的图像之上,我的按钮的 onClickListener 不再起作用。 我在哪里设置这些参数?在我的 RecyclerViewAdapter?

在您的 onBindViewHolder 中,您可以尝试将 ImageButton (holder.AppButton) 的颜色设置为透明。做这样的事情:

public void onBindViewHolder(RecyclerViewHolders holder, int position) {
 holder.AppName.setText(itemList.get(position).getName());
 holder.AppButton.setImageDrawable(itemList.get(position).getPhoto());
 //this is where you set the background to transparent...
 holder.AppButton.setBackgroundColor(Color.TRANSPARENT);
}

希望对您有所帮助,请尝试一下,如果有帮助请告诉我。