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

时间:2016-05-16 19:48:35

标签: java android image mobile android-gridlayout

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

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

android:background="#00000000"

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

1 个答案:

答案 0 :(得分:1)

onBindViewHolder中,您可以尝试将ImageButtonholder.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);
}

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