• AS 自动生成选择器 SelectorChapek



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






  • 相关阅读:
    input,textarea限制字数,实时绑定
    rem布局和vw布局的理解
    HTML5+CSS3响应式垂直时间轴,高端,大气
    谈谈前端工程化是个啥?
    js动态添加html标签和属性_手动插入meta、script、div、img等标签
    textarea换行_在textarea中如何换行的实现总汇
    css常用的颜色单位表示法
    CSS3 2D转换
    为什么设置overflow为hidden可以清除浮动带来的影响
    什么是数据交互格式?xml和json优缺点
  • 原文地址:https://www.cnblogs.com/baiqiantao/p/bcbffb037078a2ba56826df39cbc9291.html
Copyright © 2020-2023  润新知