Search code examples
androidnine-patch

Draw9Patch showing black lines


I am struggling to use the draw 9 patch. I have created the following asset using the draw 9 patch

draw9 patch

However when I embed it into the app using the following code:

<Button android:id="@+id/open_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/open_label"
        android:width="100dip"
       android:background="@drawable/simplebuttonbg"
        />

It doesn't work and shows the full image

enter image description here


Solution

  • Edit: I just fixed it in the process of documenting this question- so thought it might be useful to share: ( hope it helps someone)

    1.Basically you can't just set button background to draw 9 patch.

    1. You need to create a stateless drawable first with the data as such: in your drawables folder

      android:drawable="@drawable/simplebuttonbg_pressed"
      />
       <item
      android:state_focused="true" 
      android:state_enabled="true"
      android:drawable="@drawable/simplebuttonbg_pressed" />
      

    2. then you can apply it as a style or a background brilliantly!