按钮的风格Android

时间:2016-09-20 21:17:48

标签: java android xml button styles

谁能用风格按钮帮我?如何更改按钮的样式,我没有角度问题,我的意思是,为什么我有默认的按钮样式。 这是我的代码和显示问题

Angels1

Angles2

Value Error

style - gradient_button

Button style="@style/gradient_button" 

和文件button_grad

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

b59和y59这些是9-patch的图像。

1 个答案:

答案 0 :(得分:0)

关于您的角度问题,错误与您的图片或9补丁有关。

您可以在drawable文件夹中编写按钮样式:

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

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

将该样式应用于您的按钮:

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