我被困在试图让一些按钮在旧的API中变得透明。在ICS和forward中,我可以使用setAlpha(0);,但这在以前的API中是行不通的。如何在API 8-10中设置透明按钮?
发布于 2014-03-09 10:07:28
只需将背景设置为空
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:background="@null"/>或在代码中
button.setBackgroundResource(0);或
button.setBackgroundDrawable(null);或者您可以为主题中的按钮定义样式,这样所有按钮在默认情况下都将具有空背景。
<style name="AppTheme" parent="android:Theme">
<item name="android:buttonStyle">@style/NoBackgroundButtonStyle</item>
</style>
<style name="NoBackgroundButtonStyle" parent="android:Widget.Button">
<item name="android:background">@null</item>
</style>发布于 2014-03-09 10:21:07
如果您想将alpha应用于旧版本的整个按钮,可以使用NineOldAndroids库及其ViewHelper类。例如:
ViewHelper.setAlpha(someView, someAlphaValue);https://stackoverflow.com/questions/22280875
复制相似问题