温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android样式和主题之选择器的实例讲解

发布时间:2020-10-07 10:53:06 来源:脚本之家 阅读:141 作者:徐刘根 栏目:移动开发

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文件夹

Android样式和主题之选择器的实例讲解

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>

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

Android样式和主题之选择器的实例讲解

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对亿速云的支持。如果你想了解更多相关内容请查看下面相关链接

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI