我可以在layout.xml
中设置ImageButton背景透明使用:如何在代码中设置图像按钮的透明背景?
android:background="@android:color/transparent"
如何使用java代码完成同样的事情? 类似于ib.setBackgroundColor(???);
我可以在layout.xml
中设置ImageButton背景透明使用:如何在代码中设置图像按钮的透明背景?
android:background="@android:color/transparent"
如何使用java代码完成同样的事情? 类似于ib.setBackgroundColor(???);
这是一个简单的只有你需要设置背景颜色为透明
ImageButton btn=(ImageButton)findViewById(R.id.ImageButton01);
btn.setBackgroundColor(Color.TRANSPARENT);
这应该工作 - imageButton.setBackgroundColor(android.R.color.transparent);
做在你的XML
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButtonSettings"
android:layout_gravity="right|bottom"
android:src="@drawable/tabbar_settings_icon"
android:background="@android:color/transparent"/>
简单在您的图像按钮布局中使用此功能
android:background="@null"
使用
android:background="@android:color/transparent
或
btn.setBackgroundColor(Color.TRANSPARENT);
不给完全透明
尝试这样
ImageButton imagetrans=(ImageButton)findViewById(R.id.ImagevieID);
imagetrans.setBackgroundColor(Color.TRANSPARENT);
OR
包括这在水库的.xml文件/布局
android:background="@android:color/transparent
不使用TRANSAPENT或NULL布局因为那时button
(或通用视图)将没有更多的亮点在点击! !
我有同样的问题,最后我从Android API找到正确的属性来解决问题。它可以适用于任何视图
使用此按钮中规格
android:background="?android:selectableItemBackground"
这需要API 11
这正是我所需要的。使用'null'或'transparent'可禁用按钮反馈。 – aks
如果你想使用Android R
类
textView.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.transparent));
并且不要忘记将支持库添加到Gradle文件
compile 'com.android.support:support-v4:23.3.0'
thx询问,只需要透明线:) – CularBytes