码迷,mamicode.com
首页 > 其他好文 > 详细

AS 自动生成选择器 SelectorChapek

时间:2016-07-19 22:12:11      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:


简介
设计师给我们提供好了各种资源,每个按钮都要写一个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_pressedandroid: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 suffixDrawable state
_normal(default state)
_pressedstate_pressed
_focusedstate_focused
_disabledstate_enabled (false)
_checkedstate_checked
_selectedstate_selected
_hoveredstate_hovered
_checkablestate_checkable
_activatedstate_activated
_windowfocusedstate_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

标签:

原文地址:http://www.cnblogs.com/baiqiantao/p/bcbffb037078a2ba56826df39cbc9291.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!