When using Android Studio development, most people use plug-ins to improve development efficiency, such as the butternife,selector,,gsonformat we know from different principles to help us improve the efficiency of development, Also beautify our code structure.
Since the plug-in has so many advantages, we come to realize a simple, here, in order to facilitate our interpretation, we use Android Tintbar as an example to explain. Android Studio is based on IntelliJ idea, found on the web as if it could be developed in IntelliJ idea, and new project in Android Studio has no plugin option.
Software Environment: Java 8+intellij Idea (no, please go to IntelliJ idea download), https://www.jetbrains.com/idea/#chooseYourEdition
1. Create a new project, File->new project, if you are creating it for the first time, you need to set up the SDK for the project, click on the New button on the right, and it will find the index of the SDK for you.
The project is built as follows:
Description: Where Plugin.xml is the configuration documentation for the project, the equivalent of Androidmanifest.xml in the Android project.
<idea-plugin version= "2" > <id>com.your.company.unique.plugin.id</id> <name>plugin Display Name here</name> <version>1.0</version> <vendor email= "[email protected]" url= "/HTTP/ Www.yourcompany.com ">YourCompany</vendor> <description><! [cdata[Enter Short description for your plugin here.<br> <em>most HTML tags could be used</em> ]]></description> <change-notes><! [cdata[Add Change notes here.<br> <em>most HTML tags could be used</em>]]> </change- Notes> <!--please see Http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ ranges.html for description-<idea-version since-build= "145.0"/> <!--please see http://www.jetbrains.or G/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html on what to target different products--< ;! --Uncomment to enable plugin in all ProDucts <depends>com.intellij.modules.lang</depends> <extensions defaultextensionns= " Com.intellij "> <!--Add your extensions here--</extensions> <actions> <!--Add your act Ions--</actions></idea-plugin>
This is where our environment is built. Next we create a new code to write the plugin.
2, write the plugin
Build an action class under the new package.
Description: Action ID: Identity ID, just like the component of XML in Android @+id
Class Name: Generated classes name
Name, Description: Names and descriptions of menu options
Groups: Define where this menu option appears, for example, when you click on the menu bar edit, the first item will appear with the test option, and the anchor on the right is the location where the option appears, and defaults to the top.
The action code generated by the system for us:
public class Pluginaction extends Anaction { @Override public void actionperformed (Anactionevent e) { // Todo:insert action logic here }}
And in Plugin.xml, there's a bit more code:
<action id= "pluginID" class= "pluginaction" text= "pluginaction" description= "Plugintest" > < Add-to-group group-id= "Codemenu" anchor= "first"/> <keyboard-shortcut keymap= "$default" first-keystroke= " Alt Q "/> </action>
This is achieved when the user clicks the pluginaction menu or presses the shortcut key Alt +q after the function can be realized.
3, Create Dialog
As with action creation, Dialog can also be directly in SRC or under the name of the package right-->new->dialog, the new after the good.
Then we open the graphical interface.
Then we bind the event for when the OK button is clicked.
Plugindialog dialog = new Plugindialog (); Dialog.setvisible (TRUE);
4, write a configurable function
When your plugin needs or allows users to customize some configuration, such as my plugin allows users to define the style of code they want to generate, just open Settings->other settings will see a configuration interface.
I didn't find it because of the version difference.
5, plug-in deployment
Open the Plugin.xml file in the project, fill in the relevant information, and this information will be displayed in the plugin library, as shown in.
Clicking the Prepare Plugin button under the Bulid menu generates a jar plugin at the root of the project, as shown in
6, install the plugin
Open Android Sutdion,file, Settings, Plugins, Install plugin from disk.
7, Release plugin
If you want to make your plugin available to everyone, you can also post the plugin to the warehouse, enter the JetBrains website, fill out the relevant information of the release, submit the plugin jar package, wait for the audit to be able.
DIY a plugin for Android studio