zoukankan      html  css  js  c++  java
  • 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.






  • 相关阅读:
    Kafka 设计思路
    DBeaver——超好用可视化数据库!(墙裂推荐(づ ̄3 ̄)づ╭❤~)
    蓝图BluePrint——基于Flask框架
    SkyWalking全链路监控java项目
    win10创建ssh公钥
    mysql通过列名搜索出表名
    使用nodejs判断前端性能
    golang 栈、堆分配分析及CPU、内存性能情况
    UML图-(用例图、类图、状态图、活动图、时序图)
    linux参数调优
  • 原文地址:https://www.cnblogs.com/baiqiantao/p/bcbffb037078a2ba56826df39cbc9291.html
Copyright © 2011-2022 走看看