Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个自定义按钮,它的背景是蓝色的。我在很多活动中都使用过它,但只有一个地方我想让我的按钮透明而不影响其他。
那么如何在我的项目中使自定义按钮的一个实例变得透明呢?
您可以在自定义组件中声明变量。仅在要使组件透明的类中初始化变量。覆盖绘制方法将透明背景应用于画布。
您可以在 XML 中添加它:android:background="?android:attr/selectableItemBackground"
android:background="?android:attr/selectableItemBackground"
或者在你的代码中:buttonVariable.setBackgroundColor(Color.TRANSPARENT);
buttonVariable.setBackgroundColor(Color.TRANSPARENT);