我可以在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