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. C# 文件打印

    Process pr = new Process();                     pr.StartInfo.FileName = “C:\test.xls”;               ...

  2. php学习第一天-勤劳致富

    所谓“勤劳致富”,是很有科学依据的,且是经过我的亲身实践的. 自毕设突然转变为开发项目之后,整个天都变了.先是妹子给我订的票被强行取消,然后又是师兄的一句“***一小时就搞定了”,说明一下这个***是 ...

  3. 【HDU3394】Railway

    [题目描述] 有一个公园有n个景点,公园的管理员准备修建m条道路,并且安排一些形成回路的参观路线.如果一条道路被多条道路公用,那么这条路是冲突的:如果一条道路没在任何一个回路内,那么这条路是不冲突的 ...

  4. mfs教程(三)

    mfs文件系统(三) 使用  MooseFS 一.挂载文件系统 启动管理服务器(master server)和数据服务器(chunkservers) (chunkservers一个是必需的,但至少两个 ...

  5. 分布式缓存产品Redis和memcached比较区别(图)

  6. mysql外键约束总结

    总结三种MySQL外键约束方式 如果表A的主关键字是表B中的字段,则该字段称为表B的外键,表A称为主表,表B称为从表.外键是用来实现参照完整性的,不同的外键约束方式将可以使两张表紧密的结合起来,特别是 ...

  7. Angular问题04 模块导入错误???、BrowserModule模块重复加载???、material模块引入后报错

    1 模块导入错误 1.1 问题描述 项目启动时报错:元数据错误,错误截图如下: 1.2 问题原因 利用VsCode开发angular项目时利用自动导入出现错误 坑01:VsCode 的自动导入功能比较 ...

  8. 4-拷贝我的eclipse写安卓的配置说明

    1.下载加压: 2.配置关于jdk的javahome路径,配置过eclipse的到这里就可以了,否则百度ecplise安装配置环境变量即可: 3.以安卓项目方式加入appcompat-v7; 4.每次 ...

  9. eclipse——Maven插件创建java工程

    目录结构如下 注意默认JDK为1.5 更改默认JDK  方式一 右键工程 选中JRE1.5 Remove 双击JRE System Library 点击Finish 更改完成 方式二 配置maven ...

  10. rest-framework之序列化组件

    一:django自带序列化组件 Django内置的serializers(把对象序列化成json字符串) from django.core import serializers def test(re ...