【问题标题】:How to set set image button background to transparent in GridLayout如何在 GridLayout 中将设置图像按钮背景设置为透明
【发布时间】:2016-09-12 17:24:42
【问题描述】:

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

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

android:background="#00000000"

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

【问题讨论】:

  • 您好,但是如果灰色是实际图像的背景,那么您应该使用不同的程序将实际图像的背景设置为透明。在任何情况下,请尝试设置holder.AppButton.setBackgroundResource(R.color.mytransparent);,其中R.color.mytransparent 在您的Styles.xml 中定义为<color name="mytransparent">#00000000 </color>。试试看,如果有帮助,请告诉我。
  • @ishmaelMakitla 灰色不是图像的实际部分,它是在放入按钮时添加到图像中的东西。但我会试试你说的谢谢
  • 好的,请尝试一下,如果有帮助,请告诉我,否则我们可以探索其他解决方案。

标签: java android image mobile android-gridlayout


【解决方案1】:

在您的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);
}

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

【讨论】:

猜你喜欢
  • 2014-06-20
  • 1970-01-01
  • 1970-01-01
  • 2021-12-31
  • 1970-01-01
  • 2015-07-24
  • 2013-02-03
  • 1970-01-01
  • 2019-03-18
相关资源
最近更新 更多