• Android <Button>样式的设置方法


    在Android程序中,Button的状态有以下几种

    1、基本态

    2、获取焦点(Focus)

    3、按下(Press)  

    首先,在res/drawable下建立定义Button样式的xml文件,我将这个文件命名为button_style.xml,代码如下

     1 <?xml version="1.0" encoding="utf-8"?> 
     2 <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
     3     
     4     <item 
     5           android:state_pressed="true"  //按钮按下
     6           android:drawable="@drawable/bg_1" 
     7        />
     8     <item
     9           android:state_focus="true"     //按钮获得焦点
    10           android:drawable="@drawable/bg_2" 
    11     <item 
    12           android:drawable="@drawable/bg_3" //常态
    13         /> 
    14 </selector>

    bg_1,bg_2,bg_3为背景贴图,放在res/drawable下

    然后,在activity_main.xml中引用代码如下

    1  android:background="@drawable/button_style"
  • 相关阅读:
    HTML5 h1多层次样式问题
    spellcheck
    Favicon
    设计模式
    CSS 宽高的计算
    行高计算
    White-space 属性
    简约插件Plug-in for simple
    js类型及其判断
    前端路由
  • 原文地址:https://www.cnblogs.com/seantown/p/2793515.html
Copyright © 2020-2023  润新知