大龙的博客

常用链接

统计

最新评论

修改button -- 转



 

 

 我们要修改一下button,修改一下按下去的效果

最必要的就是修改

Java代码 
  1. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
  2.     <item   
  3.     android:state_enabled="false"  
  4.         android:drawable="@drawable/btn_red" />  
  5.     <item   
  6.         android:state_pressed="true"   
  7.         android:state_enabled="true"  
  8.         android:drawable="@drawable/btn_orange" />  
  9.     <item   
  10.         android:state_focused="true"   
  11.         android:state_enabled="true"  
  12.         android:drawable="@drawable/btn_orange" />  
  13.     <item   
  14.         android:state_enabled="true"  
  15.         android:drawable="@drawable/btn_black" />  
  16. </selector>  

 

上面的代码适合所有按钮的配置 只要修改就可以了

命名为/res/drawables /btn_custom

然后修改一下样式

 /res/values/styles.xml

<resources>
    <style name="Button" parent="@android:style/Widget.Button">
        <item name="android:gravity">center_vertical|center_horizontal</item>
        <item name="android:textColor">#FFFFFFFF</item>
        <item name="android:shadowColor">#FF000000</item>
        <item name="android:shadowDx">0</item>
        <item name="android:shadowDy">-1</item>
        <item name="android:shadowRadius">0.2</item>
        <item name="android:textSize">16dip</item>
        <item name="android:textStyle">bold</item>
        <item name="android:background">@drawable/btn_custom</item>
        <item name="android:focusable">true</item>
        <item name="android:clickable">true</item>
    </style>
</resources>

为了将整个程序的button都改为一个 修改主题

/res/values/themes.xml

<resources>
    <style name="CustomButton" parent="android:style/Theme.NoTitleBar">
        <item name="android:buttonStyle">@style/Button</item>
    </style>
</resources>
<application android:icon="@drawable/icon" 
    android:label="Custom button"
    android:theme="@style/CustomButton">

posted on 2010-06-17 19:13 大龙 阅读(516) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理