[英]How to remove white background from dialog box with custom image background?
[英]Remove white background from custom button android
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#000066" />
<stroke
android:width="2dp"
android:color="#3333D6" />
<corners
android:radius="50dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#1919FF"
android:endColor="#7171FF"
android:angle="270" />
<stroke
android:width="3dp"
android:color="#ffffff" />
<corners
android:radius="50dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
这是我用来给某些按钮设置样式的代码,但它们仍带有难看的背景(白色)显示,如下所示: http : //prntscr.com/65yzgv
如何摆脱这种白色背景?
要使背景透明,只需在其定义的布局xml文件的按钮属性中添加android:background="@android:color/transparent"
。
此问题是由于您可能正在使用棒棒糖(即API 21)编译按钮的事实而已,默认情况下,阴影是在其中。
因此,尝试我做的方式(基本上,将其样式设置为“无边界”):
yourcustombutton.xml(与您的文件相同):
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#000066" />
<stroke
android:width="2dp"
android:color="#3333D6" />
<corners
android:radius="50dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#1919FF"
android:endColor="#7171FF"
android:angle="270" />
<stroke
android:width="3dp"
android:color="#ffffff" />
<corners
android:radius="50dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
在您的活动文件中声明的按钮:
...
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer 1"
android:background="@drawable/yourcustombutton"
style="?android:attr/borderlessButtonStyle"
/>
...
一切正常...我检查了一下。 希望这可以帮助 !
在按钮中添加:
android:background="@null"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.