【发布时间】:2017-10-17 21:11:01
【问题描述】:
我正在开发一个 Android 应用程序,它有几个(下一步、返回、...等)Buttons,它们都是圆润透明的,我使用ImageButton 来处理那些Buttons,但问题是Button 周围总是有一个白色边框(我使用黑色 background,所以它非常难看),并且按钮从不显示为圆形,而是显示为某种方形。
这是我迄今为止尝试过的:
-
设置
activity_mypage.xml文件中ImageButton的背景为android:background="@android:color/transparent"到
android:background="?android:selectableItemBackground"到
android:background="?android:selectableItemBackgroundBorderless"甚至到
android:background="@null"但在 .xml 方面似乎没有任何效果。
-
我在 MyPage.java 文件上尝试了以下操作:
myBtn.setBackgroundResource(0);还有
myBtn.setBackground(null);
我所做的任何事情似乎都没有效果,结果仍然相同(尽管它从 Button 周围删除了灰色边框,但它们都没有使 Button 完全透明)
这是应用任何这些属性后相同Button 的屏幕截图(如果我将其仅应用于xml 或仅应用于java 文件或两者都没有关系,因为所有结果都是同样):
这是我在 xml 中的 Buttons 之一的 xml 代码:
<ImageButton
android:id="@+id/my_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="26dp"
android:layout_marginEnd="37dp"
android:layout_marginRight="37dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="@mipmap/my_btn"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintRight_creator="1"
android:background="@android:color/transparent"
/>
这是 .java 文件中的代码:
ImageButton myBtn= (ImageButton) findViewById(R.id.my_btn);
myBtn.setBackground(null);
myBtn.setBackgroundResource(0);
我真的迷失了,我为此查询找到的每个结果都建议了上述方法之一,但这些方法似乎都不适合我..
【问题讨论】:
-
您的图片周围似乎有白色边框。
-
你能把你的图片(my_btn)也发上来吗
-
@VivekMishra 我之前尝试了许多透明图像,但它们都有相同的问题,Here 是我使用的同一图像的链接。
-
你是否尝试设置 android:src 而不是 app:srcCompat
-
也可能与问题有关:您不应将任何资源放在
mipmap文件夹中,它们仅用于启动器图标。将其移至相应的drawable文件夹。