简介
设计师给我们提供好了各种资源,每个按钮都要写一个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 forSelectorChapek
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.