Search code examples
androidandroid-viewnine-patchandroid-styles

Button with 9-patch image background doesn't stretch correctly


I have a problem with custom background for button. There's my 9-patch: resulting image

Same in Draw 9-patch:

in Draw 9-patch

And, finally, result on device's screen:

result on screen

And that's the code, describing my button:

Layout:

<Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="New Button"
        style="@style/button"/>

Style:

<style name="button">
    <item name="android:background">@drawable/button</item>
    <item name="android:textColor">@color/button_text</item>
</style>

@drawable/button:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false" >
        <bitmap android:src="@drawable/button_test"/>
    </item>
</selector>

File name of drawable in res folders is button_test.9.png

Do you have any ideas why it doesn't work? Thank you.


Solution

  • remove bitmap tag inside item tag, add android:drawable attribute within item tag