Reputation: 63
How can I make a button with this theme? Blue and glowing box:
Upvotes: 3
Views: 145
Reputation: 5410
This can be done by creating a 9-patch image based on that custom button image (and optionally for the selected / pushed button state graphics). The 9-patch format is basically a PNG file with special marker pixels that slice the button graphic into segments so it can dynamically grow and shrink according to the final size of the button view. The Android SDK comes with a tool for creating those 9-patch images.
When this is done you need to create a state list XML resource file in the drawable
resource directory. That state list references those 9-patch images for each button state (normal, pressed, etc.). The SDK documentation explains it nicely here: http://developer.android.com/guide/topics/ui/controls/button.html#CustomBackground
Code excerpt from that page:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed"
android:state_pressed="true" />
<item android:drawable="@drawable/button_focused"
android:state_focused="true" />
<item android:drawable="@drawable/button_default" />
</selector>
In the end you can assign that XML drawable to your button as a background image resource like as follows:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some label text"
android:background="@drawable/my_button_state_list" />
Upvotes: 3