你好,游客 登录 注册 搜索
背景:
阅读新闻

Android自定义按钮样式

[日期:2012-10-05] 来源:Linux社区  作者:zhy_cheng [字体:大 中 小]

使得按钮在不同的状态有不同的背景图片是本篇的主要类容

在res/drawable下新建一个buttonstyle.xml文件,这个文件用于描述按钮的样式

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <selector xmlns:Android="http://schemas.android.com/apk/res/android" > 
  3.     <item android:state_pressed="true" android:drawable="@drawable/btn_p"/> 
  4.     <item android:state_pressed="false" android:drawable="@drawable/btn_n"/> 
  5. </selector> 

还有很多的样式如下图

在布局文件中添加一个Button,使用buttonstyle.xml

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:layout_width="fill_parent" 
  4.     android:layout_height="fill_parent" 
  5.     android:orientation="vertical" > 
  6.  
  7.     <TextView 
  8.         android:layout_width="fill_parent" 
  9.         android:layout_height="wrap_content" 
  10.         android:text="@string/hello" /> 
  11.  
  12.     <Button 
  13.         android:id="@+id/button1" 
  14.         android:layout_width="wrap_content" 
  15.         android:layout_height="wrap_content" 
  16.         android:background="@drawable/buttonstyle" 
  17.         /> 
  18.  
  19. </LinearLayout> 

这样就完成了Button的样式。

linux
相关资讯       Android开发入门教程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款