2017-10-17 70 views
0

我正在开发一个Android应用程序,它有几个(Next,Back,...等)Buttons这些都是圆形和透明的,我使用ImageButton那些Buttons ,但问题是Button(我使用黑色background,因此它非常难看)上总是有一个白色边框,并且该按钮从未显示为圆形,表现为某种方形的形状。无法摆脱ImageButton周围丑陋的边框

这里是我试过到目前为止:

  1. activity_mypage.xml文件设置ImageButton的背景

    android:background="@android:color/transparent" 
    

    ,并

    android:background="?android:selectableItemBackground" 
    

    android:background="?android:selectableItemBackgroundBorderless" 
    

    甚至

    android:background="@null" 
    

    但似乎没有任何的.XML边工作。

  2. ,我试图在MyPage.java文件如下:

    myBtn.setBackgroundResource(0); 
    

    myBtn.setBackground(null); 
    

似乎没有任何工作对我所做不断产生相同的(尽管它从Button附近删除灰色边框,但没有一个使得Button完全透明)

这是按钮的截图应用任何上述前:
Before Applying any of the above settings/attributes

而且这是同Button截图应用任何这些属性(的并不重要,如果以后我申请它只是在xml或仅java文件,或同时,因为所有的结果都是一样的):
enter image description here

这是在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); 

我真的失去了在这个每个结果我发现这个查询已经提出的上述方法之一,但没有这些似乎为我工作..

+0

看起来你的图像周围有白色边框。 –

+0

你可以发布你的图像(my_btn)也 – UltimateDevil

+0

@VivekMishra我曾尝试过一些透明的图像,但他们都有同样的问题,[这里](https://imgur.com/a/VZg3C)是这个链接我使用的相同图像。 –

回答

0

只要改变

android:background="@android:color/transparent" 

android:background="@null" 
+0

他做到了,但没有奏效。 – nhoxbypass

+0

我已经尝试了这两个问题,因为某些原因不起作用。 –

0

与此

android:src="@mipmap/yourimage" 

,而不是尝试

app:srcCompat="@mipmap/my_btn"

+0

我只是试过,它也不工作.. –

+0

@LawaFazil你想要什么样的动画? –

0

可以使用ImageView代替ImageButton,所以不会发生的背景问题

<ImageView 
      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" 
      android:src="@mipmap/my_btn" 
     /> 
+0

我希望点击按钮时点击“动画”,这就是为什么我用ImageButton –

+0

@LawaFazil告诉我,你有活动或活动AppCompactActivity延长你的活动类 – UltimateDevil

0

添加到您的按钮

android:background="@drawable/template" 

,并在您绘制文件夹 创建一个文件命名为模板,并添加这个代码吧

<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
<item android:state_pressed="true" android:drawable="@drawable/btn2imagePressed"></item> 
<item android:drawable="@drawable/btn1imageNotPressed"></item> </selector> 
+0

我发现是什么原因造成的问题我将发布解决方案现在.. –

0

所以读完som张贴的答案e和在我的代码我注意到,icon被错误地装载到我mipmap目录,而不是drawables,这是因为当我进口icons我选择New->Image Asset代替Vector Asset造成的建议玩弄我的“图标'失去其透明度...

感谢大家的答复和答案。