zoukankan      html  css  js  c++  java
  • 安卓天天练练(四)drawable state 属性

    今天又作茧自缚(item 写成 itme ╮(╯▽╰)╭ elipse还自动闭合了标签,来回查查查看报错,为啥点击无效呢!)

    真欠抽,怪不得上班地铁上被个sb踢到脚趾头(目测有可能是同家公司的..同站下车他直奔中行ATM,西楼面熟)

    在drawable下建的xml,IDE选selector类型

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
                <item android:drawable="@drawable/btn" android:state_pressed="false"></item>
                <item android:drawable="@drawable/btnhover" android:state_pressed="true"></item>           
    </selector>

    layout中的主文件main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.narumi.android_7_3.MainActivity" >
    
        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/mybutton"  
            android:background="@drawable/btn"
             />
    
    </RelativeLayout>

    一行java也不用写,p了两张图片,此例结束。

    备注:

    android:state_pressed 是否按下,如一个按钮触摸或者点击。
    android:state_focused 是否取得焦点,比如用户选择了一个文本框。
    android:state_hovered 光标是否悬停,通常与focused state相同,它是4.0的新特性
    android:state_selected 被选中,它与focus并不相同,如一个list view 被选中,它的各个子组件可能通过方向键被选中。
    android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。
    android:state_checked 被checked了,如:一个RadioButton可以被check了。
    android:state_enabled 能够接受触摸或者点击事件
    android:state_activated 被激活。
    android:state_window_focused 应用程序是否在前台,当有通知栏拉下或者对话框弹出的时候应用程序就不在前台了。

    如果有多个item,程序将自动从上到下匹配,最先匹配的将得到应用。(不是通过最佳匹配)

    如果一个item没有任何的状态说明,那么它将可以被任何一个状态匹配。

  • 相关阅读:
    中文词频统计
    【大数据应用期末总评】Hadoop综合大作业
    【大数据作业十一】分布式并行计算MapReduce
    【大数据作业十】分布式文件系统HDFS 练习
    【大数据作业九】安装关系型数据库MySQL 安装大数据处理框架Hadoop
    【爬虫综合大作业】腾讯视频——大家到底都在看什么?!
    【大数据作业七】爬取全部的校园新闻
    【大数据作业六】获取一篇新闻的全部信息
    【大数据作业五】理解爬虫原理
    【大数据作业四】中文词频统计
  • 原文地址:https://www.cnblogs.com/haimingpro/p/4666915.html
Copyright © 2011-2022 走看看