简体   繁体   中英

Button's style Android

Who can help me with style button? How I must change button's style, that I haven't problems with angles, I mean, Why I have default style of button. this is my code and display problem

Angels1

Angles2

Button style="@style/gradient_button" 

style - gradient_button

<style name="button_common">
 <item name="android:layout_height">wrap_content</item>
 <item name="android:layout_width">wrap_content</item>
 <item name="android:textColor">#ffffff</item>
 <item name="android:textSize">14sp</item>
</style>
    <style name="gradient_button" parent="@style/button_common">
        <item name="android:background">@drawable/button_grad</item>
    </style>

and file button_grad

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_enabled="true"
        android:state_pressed="false"
        android:drawable="@drawable/b59" />
    <item
        android:state_enabled="true"
        android:state_pressed="true"
        android:drawable="@drawable/y59" />
    <item
        android:state_enabled="false"
        android:drawable="@drawable/b59" />
</selector>

b59 and y59 these are image with 9-patch.

About your angle's problem the error is about your images or about 9-patch.

You can write the style for button in your drawable folder:

style_button.xml :

<style name="button_common">
 <item name="android:layout_height">wrap_content</item>
 <item name="android:layout_width">wrap_content</item>
 <item name="android:textColor">#ffffff</item>
 <item name="android:textSize">14sp</item>
</style>

selector.xml in your drawable folder:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_enabled="true"
        android:state_pressed="false"
        android:drawable="@drawable/b59" />
    <item
        android:state_enabled="true"
        android:state_pressed="true"
        android:drawable="@drawable/y59" />
    <item
        android:state_enabled="false"
        android:drawable="@drawable/b59" />
</selector>

Apply that style to your button :

<Button
                android:id="@+id/btn"
                style="@style/style_button"
                android:layout_centerVertical="true"
                android:background="@drawable/selector"
                android:drawablePadding="10dp"
                android:text="btnText" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM