开发Android Studio插件(IntelliJ IDEA

2020-08-18  本文已影响0人  蓝不蓝编程

操作步骤

  1. 打开IntelliJ IDEA,创建新插件工程


  2. 新建的工程如下图:


  3. 点击src目录,创建Action


  4. 指定Action ID/Class Name/Name/Description(随性即可),指定加入的菜单
    本例加入的菜单是Edit菜单.


  5. 新建Action后如下图:


  6. 修改TestAction的actionPerformed函数如下:
public void actionPerformed(AnActionEvent e) {
    final Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (null == editor) {
        return;
    }
    SelectionModel model = editor.getSelectionModel();
    final String selectionTxt = model.getSelectedText();
    if (selectionTxt != null && !selectionTxt.isEmpty()) {
        Messages.showMessageDialog(selectionTxt, "已选择文本", Messages.getInformationIcon());
    }
}
  1. 运行
  1. 打包
    右键点击工程根目录,选择“Prepare Plugin Module ...”



    完成后,根目录下多了一个jar或zip文件,这个就是插件包.


  2. Android Studio安装插件包

完整源代码

https://gitee.com/cxyzy1/plugin-demos

参考资料

Android Studio插件开发入门篇

上一篇 下一篇

猜你喜欢

热点阅读