Question

Im stuck on trying to get some buttons to be transparent in older API's. In ICS and forward I can use setAlpha(0); but that wont work in the older once. How can I set the buttons transparent in API 8-10?

Was it helpful?

Solution

Just set background to null

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:background="@null"/>

Or in code

button.setBackgroundResource(0);

or

button.setBackgroundDrawable(null);

Or you can define a style for a button in your theme so all buttons will have null background by default

<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>

OTHER TIPS

If you want to apply alpha to the whole button on older Android versions, you can use NineOldAndroids library, with its ViewHelper class. For example:

    ViewHelper.setAlpha(someView, someAlphaValue);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top