【发布时间】:2012-12-02 10:36:39
【问题描述】:
默认情况下,ICS 中的按钮有点透明。 我想实现该按钮保留其所有属性(形状、颜色、按下状态),但不要使其不透明。
我怎样才能做到这一点?
提前致谢!
【问题讨论】:
-
您需要为此按钮提供自己的背景。
标签: java android android-layout button transparency
默认情况下,ICS 中的按钮有点透明。 我想实现该按钮保留其所有属性(形状、颜色、按下状态),但不要使其不透明。
我怎样才能做到这一点?
提前致谢!
【问题讨论】:
标签: java android android-layout button transparency
您可以为扩展默认样式的按钮创建一个样式(如果您使用的是 Holo.Light):
<style name="GreenButton" parent="android:Widget.Holo.Button">
<item name="android:background">#00ff00</item>
</style>
然后手动将样式应用到带有 style 属性的按钮,或者,如果您想更改所有按钮,请在应用的主题中设置 buttonStyle:
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:buttonStyle">@style/GreenButton</item>
</style>
【讨论】:
您也可以在按钮下方使用纯色背景的视图。鉴于您有相对布局,这对您很有帮助。
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button"
android:layout_alignLeft="@id/button"
android:layout_alignBottom="@id/button"
android:layout_alignRight="@id/button"
android:background="@android:color/black"
/>
【讨论】: