如何设置样式为Android的一个按钮? [英] How to set Style for a button in Android?

查看:312
本文介绍了如何设置样式为Android的一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在res文件夹中定义的下面的文件。

I have defined the below files in res folder.

styles_apptheme.xml

styles_apptheme.xml

<?xml version="1.0" encoding="utf-8"?>

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="ButtonAppTheme" parent="android:Widget.Holo.Light.Button">
      <item name="android:background">@drawable/apptheme_btn_default_holo_light</item>
  </style> 
</resources>

themes_apptheme.xml

themes_apptheme.xml

<?xml version="1.0" encoding="utf-8"?>

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="AppTheme" parent="@style/_AppTheme"/>

  <style name="_AppTheme" parent="Theme.AppCompat.Light">

    <item name="android:editTextBackground">@drawable/apptheme_edit_text_holo_light</item>

    <item name="android:buttonStyle">@style/ButtonAppTheme</item>

  </style>

</resources>

在我Layout.xml文件中,我定义我的按钮,如下

In my Layout.xml file, i have defined my button as below

<Button
        android:id="@+id/btnAddTitle"
        android:layout_below="@id/edEnterTitleValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_AddTitle"
        android:layout_margin="20dp"
/>

如果我下面的行添加到按钮上述观点来看,

If i add the below line to the button view above,

android:background="@style/ButtonAppTheme"

应用程序崩溃说,绘制资源应该为背景的属性进行设置。

Application crashes saying that drawable resource should be set for the background attribute.

所以我创建以下文件绘制 - abc.xml

So i created the below drawable file - abc.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/apptheme_btn_default_normal_holo_light" />
    <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/apptheme_btn_default_disabled_holo_light" />
    <item android:state_pressed="true"
        android:drawable="@drawable/apptheme_btn_default_pressed_holo_light" />
    <item android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/apptheme_btn_default_focused_holo_light" />
    <item android:state_enabled="true"
        android:drawable="@drawable/apptheme_btn_default_normal_holo_light" />
    <item android:state_focused="true"
        android:drawable="@drawable/apptheme_btn_default_disabled_focused_holo_light" />
    <item
         android:drawable="@drawable/apptheme_btn_default_disabled_holo_light" />
</selector>

如果我设置的android:背景=@绘制/ ABC我没有看到风格的按钮设置

If i set android:background="@drawable/abc" i dont see the style set in the button.

所以,请让我知道我可以设置样式的按钮。

So please let me know how i can set the style for the button.

感谢。

推荐答案

Android的按钮制作在线工具来生成按钮code为Android应用程序。 Android的API提供绘图资源,其中的XML文件定义的几何形状,包括颜色,边框和梯度。
这些按钮是基于形状绘制XML code载入速度较快的比较正常的PNG按钮生成。您可以在设置面板可以自定义按钮的属性并获得源$ C ​​$ C。

Android Button Maker is online tool to generate buttons code for Android Apps. Android API provide Drawable Resources where XML file defines geometric shape, including colors, border and gradients. These button is generating based on shape drawable XML code which load faster compare to normal png buttons. You can customize button properties in setting panel and get source code.

勾选此链接按钮制作

没有需要破解的大脑......这个工具使简单

No need to crack brains...this tool make it simple

这篇关于如何设置样式为Android的一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆