Android学习笔记之样式和主题之选择器

(1)布局文件

<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=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="189dp"
        android:layout_marginLeft="55dp"
        android:textColor="@color/button_selector"
        android:text="测试颜色列表状态" />

</RelativeLayout>

需要在按钮里边使用:android:textColor="@color/button_selector"

(2)需要在res目录下创建一个color文件夹

button-selector文件内容如下:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true" android:color="#ffff0000"/>
    <item android:state_focused="true" android:color="#ff0000ff"/>
    <item android:color="#ff000000"/>

</selector>

其他文件不做修改,默认的就可以

时间: 2024-08-11 07:35:50

Android学习笔记之样式和主题之选择器的相关文章

android学习笔记38——样式和主题

Style.Theme 样式和主题资源都是用于android应用的美化操作. 样式:一组格式的集合,可重复使用. android的样式资源存放与res/values文件夹下,其根元素为<resources.../>,该元素内可包含多个<style>子元素,每个<style>定义一个样式.\ <style>元素指定如下属性: 1.name 2.parent:指定该样式继承的父类样式.当样式继承某个父类样式时,该样式会获得父样式中定义的全部样式:同时,当前样式也

【Android学习笔记】DatePickerDialog和TimePickerDialog日期选择器和时间选择器

(1)布局文件 <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:p

十三、Android学习笔记_Andorid控件样式汇总

<!-- 设置activity为透明 --> <style name="translucent"> <item name="android:windowBackground">@color/translucent</item> <item name="android:windowIsTranslucent">true</item> <item name="an

Android学习笔记_75_Andorid控件样式汇总

<!-- 设置activity为透明 --> <style name="translucent"> <item name="android:windowBackground">@color/translucent</item> <item name="android:windowIsTranslucent">true</item> <item name="an

Android学习笔记二十九之SwipeRefreshLayout、RecyclerView和CardView

Android学习笔记二十九之SwipeRefreshLayout.RecyclerView和CardView 前面我们介绍了AlertDialog和几个常用的Dialog,ProgressDialog进度条提示框.DatePickerDialog日期选择对话框和TimePickerDialog时间选择对话框.这一节我们介绍几个新的API控件SwipeRefreshLayout.RecyclerView和CardView,这几个API控件都是google在Android5.0推出的.下面我们来学

Android学习笔记之mainfest文件中android属性

Android学习笔记之mainfest文件中android属性 - Impossible is nothing - 博客频道 - CSDN.NET 以前的零散笔记, 共享一下, 有错误的地方还请指正. android:allowTaskReparenting 是否允许activity更换从属的任务,比如从短信息任务 切换到浏览器任务.---------------------------------------------------------------------------------

Android 学习笔记(二七):Menu

Menu由两种形式,Option menu和Context menu.前者是按下设备的Menu硬按钮弹出,后者是长按widget弹出. Option Menu 当我们按下Menu的硬件按钮时,Option Menu将被触发显示,最多可以显示6个选项的icon菜单,如果选项多于6个,第6个选项显示为“More“,点击可以进入扩展菜单.我们将在Android学习笔记(十一):Activity-ListView的例子一的基础上来学习Option Menu,也就是一个基于activity的菜单. 在这个

【转】 Pro Android学习笔记(五二):ActionBar(5):list模式

可以在action bar中加入spinner的下来菜单,有关spinner,可以参考Pro Android学习笔记(二十):用户界面和控制(8):GridView和Spinner. list的样式和theme有关,如果theme设置不正确,还可能会出现异常. 相关的代码如下: public class ListActionBarDemo extends SearchTestCase3 implements OnNavigationListener{ //List触发的回调函数接口    @Ov

【转】Pro Android学习笔记(七):了解Content Provider(下上)

我们通过一个Content Provider小例子进行详细说明.数据源是一个SQLite数据库,名字为books.db,该数据库只含有一个表格,名字为books.表格中含有name,isbn,author,created_date和modified_date几列.我们通过一个名为BookProvider的内容提供者将数据源运行封装,并对外提供增删改查的接口. 首先:定义Content Provider的结构 创建一个Provider,我们首先需要定义好这个provider的结构.通过consta