1.介绍

2.xml文件属性介绍

3.实例演示

<1>新建drawable文件

app--->src---->main---->res---->drawable ,选中drawable文件夹,右击new--->drawable resource file

<2>源码

(1)主界面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="用户名" />

        <EditText
            android:id="@+id/editText"
            android:textColor="@drawable/text_color"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:hint="请输入用户名"
            android:inputType="textPersonName" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密码" />

        <EditText
            android:id="@+id/editText3"
            android:layout_width="wrap_content"
            android:textColor="@drawable/text_color"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:hint="请输入密码"
            android:inputType="textPassword" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button"
            android:background="@drawable/background_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_marginLeft="20dp"
            android:text="登录" />

        <Button
            android:id="@+id/button2"
            android:background="@drawable/background_img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_marginLeft="20dp"
            android:text="取消" />
    </LinearLayout>
</LinearLayout>

(2)background_img.xml文件

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

(3)text_color.xml文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true"
        android:color = "#f44"></item>
    <item android:state_focused="false"
        android:color="#000000"></item>
</selector>

Android StateListDrawable资源的使用(文本的高亮显示)的更多相关文章

  1. 处女男学Android(七)---Android 应用资源之StateListDrawable

    前言 本篇Blog将记录关于Android应用资源中最经常使用的一个Drawable资源--StateListDrawable,本来说应当继续写UI方面的内容,突然跳到应用资源这边,主要是由于之前写界 ...

  2. StateListDrawable 资源

    StateListDrawable 用于组织多个 Drawable 对象.当使用 StateListDrawable 作为目标组件 的背景.前景图片时,StateListDrawable 对象所显示的 ...

  3. 使用(Drawable)资源——StateListDrawable资源

    StateListDrawable用于组织多个Drawable对象.当使用StateListDrawable作为目标组件的背景.前景图片时,StateListDrawable对象所显示的Drawabl ...

  4. 34.Android之资源文件res里drawable学习

    我们经常看到android工程资源文件res下drawable如ldpi.mdpi.hdpi.xhdpi.xxhdpi文件,今天我们学习了解下. (1)drawable-hdpi里面存放高分辨率的图片 ...

  5. Android控件_TextView(显示文本框控件)

    一.TextView控件的常用属性  1.android:id——控件的id   2.android:layout_width——设置控件的宽度 wrap_content(包裹实际文本内容) fill ...

  6. android应用资源预编译,编译和打包全解析

    我们知道,在一个APK文件中,除了有代码文件之外,还有很多资源文件.这些资源文件是通过Android资源打包工具aapt(Android Asset Package Tool)打包到APK文件里面的. ...

  7. Android应用资源

    Java刚開始学习的人直接在Java源代码使用"hello" 和123 类型的字符串和整型.但时间长了就会忘记当初定义的原因,有经验的或许会定义字符串常量ResultSet.TYP ...

  8. Android xml资源文件中@、@android:type、@*、?、@+含义和区别

    一.@代表引用资源 1.引用自定义资源.格式:@[package:]type/name android:text="@string/hello" 2.引用系统资源.格式:@andr ...

  9. android 学习资源总结

    http://android-arsenal.com/free   国外的android分类资源网站 http://www.ibm.com/developerworks/cn/topics/   IB ...

随机推荐

  1. Android 创建项目出现No resource found that matches the given name Theme.AppCompat.Light

    关于为何出现No resource found that matches the given name ‘Theme.AppCompat.Light’的原因 这边博客已经写的很清楚了 大家可以参考一下 ...

  2. WebFlux04 SpringBootWebFlux集成MongoDB之Windows版本、WebFlux实现CRUD、WebFlux实现JPA、参数校验

    1 下载并安装MongoDB 1.1 MongoDB官网 1.2 下载 solutions -> download center 1.3 安装 双击进入安装即可 1.3.1 安装时常见bug01 ...

  3. Java-Decimal

    import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.NumberFormat; public c ...

  4. 10个强大的Javascript表单验证插件推荐

    创建一个JavaScript表单验证插件,可以说是一个繁琐的过程,涉及到初期设计.开发与测试等等环节.实际上一个优秀的程序员不仅是技术高手,也应该是善假于外物的.本文介绍了10个不错的JavaScri ...

  5. Django框架 之 form组件

    Django框架 之 form组件 浏览目录 Form介绍 普通的登录 使用form组件 Form详情 常用字段 校验 进阶 使用Django Form流程 一.Form介绍 我们之前在HTML页面中 ...

  6. Flask 之 上下文管理

    Flask上下文管理 分类: 请求上下文管理 应用上下文管理 请求上下文管理 request a. 温大爷:wsig b. 赵毅: ctx = ReuqestContext(session,reque ...

  7. Cookie的有效访问路径

    Cookie 的 作用范围: Cookie详解:https://www.cnblogs.com/handsomecui/p/6117149.html 可以作用当前目录和当前目录的子目录. 但不能作用于 ...

  8. Selenium如何定位动态id/class的元素?

     今天再给大家分享一个定位不到元素的原因——动态id. 没有打开新页面.没有alert.没有frame.加了等待时间,但是还是定位不到元素?很有可能是你要定位的元素的属性是动态的,即每次打开页面,这个 ...

  9. oracle数据库之数据插入、修改和删除

    作为一合格的测试人员对数据库的单表查询.多表查询.分组查询.子查询等等这些基本查询方法还是要会的.不然到企业中,容易被一些人鄙视,或者说如果数据库学不好,表查不明白,那么对自己能力来说也是一种侮辱,因 ...

  10. Controller级别的异常处理过滤器IExceptionFilter

    1,系统自带的HandleErrorAttribute类继承自IExceptionFilter,是MVC的默认实现. 同时设置web.config <system.web> <cus ...