简介


设计师给我们提供好了各种资源,每个按钮都要写一个selector是不是很麻烦?
这么这个插件就为解决这个问题而生,你需要做的就是按照规范命名就好了,其他一键搞定。

问题:
1、并非只能放在drawable-xhdpi目录下,放在任何drawable目录下均可
2、同样右键在任何drawable目录上均有效
3、不能识别mipmap目录下的文件,同样右键在任何mipmap目录上均无效
4、如果要生成的文件已经存在,则生成失败,而不会覆盖,这个一定要注意!

测试

测试一
原有的文件:ic_launcher_normal.png和ic_launcher_pressed.png
生成的文件:ic_launcher.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_launcher_normal" android:state_pressed="false"/>
    <item android:drawable="@drawable/ic_launcher_pressed" android:state_pressed="true"/>
</selector>

测试二
原有的文件:ic_launcher_normal.png和ic_launcher_pressed.png和ic_launcher_selected.png
生成的文件:ic_launcher.xml(注意,需手动把之前生成的文件删除才会重新生成)
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_launcher_normal" android:state_pressed="false" android:state_selected="false"/>
    <item android:drawable="@drawable/ic_launcher_pressed" android:state_pressed="true" android:state_selected="false"/>
    <item android:drawable="@drawable/ic_launcher_selected" android:state_pressed="false" android:state_selected="true"/>
</selector>

官方文档


SelectorChapek for Android

This Android Studio plugin automatically generates自动生成 drawable selectors from appropriately适当的 named Android resources.

How to install it:

  • in Android Studio: go to Preferences→Plugins→Browse repositories and search for SelectorChapek or
  • download it and install via Preferences→Plugins→Install plugin from disk

How to use it:

1) Right-click folder文件夹右键 with your resources e.g 'drawable-xhdpi' 2) Select 'Generate Android Selectors' 3) All selectors automagically appear in the 'drawable' folder!

Naming convention命名规则:

In order of plugin to work, resources need to be appropriately named. The plugin supports png or nine-patch files with certain suffices后缀 anywhere in the file name. You can also combine整合 any suffixes together.

Mapping

File name suffix Drawable state
_normal (default state)
_pressed state_pressed
_focused state_focused
_disabled state_enabled (false)
_checked state_checked
_selected state_selected
_hovered state_hovered
_checkable state_checkable
_activated state_activated
_windowfocused state_window_focused

Wishlist

  • UI which will tell you which selectors will be generated
  • possibility to change naming mapping
Pull requests are welcomed!

Why 'Chapek'?

Karel Čapek was a famous Czech捷克 writer, inventor发明者 of the word 'robot'机器人. The word comes from Czech word 'robota', which means 'hard manual labor处理繁重的劳动'. As with Čapek's robots, this plugin will remove your unnecessary manual labor. See our other Czech personalities who help with #AndroidDev.

AS 自动生成选择器 SelectorChapek的更多相关文章

  1. IntelliJ IDEA 中自动生成 serialVersionUID 的方法

    as, idea plugin中搜如下关键字,并安装该插件: GenerateSerialVersionUID 如上图所示,创建一个类并实现Serializable接口,然后按alt+Enter键,即 ...

  2. 用jquery实现文章自动生成二级目录(续)

    前文:用jquery实现文章自动生成二级目录. 使用方法的补充 我们可以把我们的js和css上传到博客园,然后在页面HTML代码中使用他们. 发现的一些问题 在我把我的js放到自己的博客园上运行之后发 ...

  3. .NET6使用DOCFX自动生成开发文档

    本文内容来自我写的开源电子书<WoW C#>,现在正在编写中,可以去WOW-Csharp/学习路径总结.md at master · sogeisetsu/WOW-Csharp (gith ...

  4. SQL Server镜像自动生成脚本

    SQL Server镜像自动生成脚本 镜像的搭建非常繁琐,花了一点时间写了这个脚本,方便大家搭建镜像 执行完这个镜像脚本之后,最好在每台机器都绑定一下hosts文件,不然的话,镜像可能会不work 1 ...

  5. 使用mybatis-generator在自动生成Model类和Mapper文件

    使用mybatis-generator插件可以很轻松的实现mybatis的逆向工程,即,能通过表结构自动生成对应的java类及mapper文件,可以大大提高工作效率,并且它提供了很多自定义的设置可以应 ...

  6. 使用python自动生成docker nginx反向代理配置

    由于在测试环境上用docker部署了多个应用,而且他们的端口有的相同,有的又不相同,数量也比较多,在使用jenkins发版本的时候,不好配置,于是想要写一个脚本,能在docker 容器创建.停止的时候 ...

  7. 9.1.3 .net framework通过业务逻辑层自动生成WebApi的做法

    首先需要说明的是这是.net framework的一个组件,而不是针对.net core的.目前工作比较忙,因此.net core的转换正在编写过程中,有了实现会第一时间贴出来. 接下来进入正题.对于 ...

  8. 9.1.2 asp.net core 自动生成组合查询

    在做系统的时候,经常遇到前台录入一大堆的查询条件,然后点击查询提交后台,在Controller里面生成对应的查询SQL或者表达式,数据库执行再将结果返回客户端. 例如如下页面,输入三个条件,日志类型. ...

  9. mybatis-generator-gui--一个mybatis代码自动生成界面工具

    mybatis-generator-gui是什么 介绍mybatis-generator-gui之前,有必要介绍一下什么是mybatis generator(熟悉的同学可以跳过这一节).我们都知道,通 ...

随机推荐

  1. input, textarea,监听输入事件

    IE使用'propertychange'事件监听,其它浏览器使用'input'事件测试了IE7-10, Chrome, FF, 输入没有问题.♥但在IE9下,  删除,  回退,  Ctrl+X 没有 ...

  2. Jquery的外部链接和编写样式

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></ ...

  3. js 求两个日期之间相差天数

    //求两个日期之间的相差天数 function daysBetween(DateOne, DateTwo) { var OneMonth = DateOne.substring(5, DateOne. ...

  4. yii2源码学习笔记(二)

    yii\base\Object代码详解 <?php /** * @link http://www.yiiframework.com/ * @copyright Copyright (c) 200 ...

  5. win7 IIS7.0 【IIS 管理器无法验证此内置帐户是否有访问权】

    异常信息: 服务器配置为将传递身份验证和内置帐户一起使用,以访问指定的物理路径.但是,IIS 管理器无法验证此内置帐户是否有访问权.请确保应用程序池标识具有该物理路径的读取访问权.如果此服务器加入到域 ...

  6. python学习第十六天 --继承进阶篇

    这一章节主要讲解面向对象高级编程->继承进阶篇,包括类多继承介绍和继承经典类和新式类属性的查找顺序不同之处. 多继承 上一章节我们讲到继承,子类继承父类,可以拥有父类的属性和方法,也可以进行扩展 ...

  7. USACO1.5 Checker Challenge(类n皇后问题)

    B - B Time Limit:1000MS     Memory Limit:16000KB     64bit IO Format:%lld & %llu   Description E ...

  8. Solr In Action 笔记(3) 之 SolrCloud基础

    Solr In Action 笔记(3) 之 SolrCloud基础 在Solr中,一个索引的实例称之为Core,而在SolrCloud中,一个索引的实例称之为Shard:Shard 又分为leade ...

  9. QWaitCondition(和Java的Notify机制非常相像)

    QT通过三种形式提供了对线程的支持.它们分别是,一.平台无关的线程类,二.线程安全的事件投递,三.跨线程的信号-槽连接.这使得开发轻巧的多线程Qt程序更为容易,并能充分利用多处理器机器的优势.多线程编 ...

  10. QT美化界面的文章(真的很美)

    http://www.hookr.cn/tag/qt http://blog.csdn.net/yiyaaixuexi/article/category/758470 http://www.qtcn. ...