介紹Android Studio上的幾個插件
來自:http://blog.csdn.net/maosidiaoxian/article/details/44992655
以下所有插件都可以在Idea的插件庫中找到,如果你與我一樣在Android Studio中無法搜索到任何插件的話,可以用離線安裝的方式,先在IDEA插件的站點(http://plugins.jetbrains.com /category/?idea&category_id=all)上搜索下載,然后在Android Studio 的插件管理中選擇 Install plugin from disk。注意,可能需國內或許不能訪問才能打開。
1. Android Parcelable code generator
顧名思義,這是個生成實現了Parcelable接口的代碼的插件。
在你的類中,按下alt + insert鍵彈出插入代碼的上下文菜單,你會看到在下面有一個Parcelable,如下所示。選擇它之后,就會在你的類當中插入實現了Parcelable接口的代碼。從此不用再手動寫Parcelable代碼,感覺怎樣呢?
2. AndroidCodeGenerator
它的介紹說是可以生成ViewHolder和findView方法的代碼。不過怎么生成findView方法的代碼我還沒找到,但生成ViewHolder也是挺酷炫的。
在你的Adapter實現類的getView當中,將光標定位到你的布局文件的ID的變量中,按Alt+Insert插件代碼,可以看到多了一項Create view holder,如下圖。
選擇它之后,它會根據布局文件里的聲明了id的元素,為你生成對應的ViewHolder代碼,如下所示:
public class ViewHolder { public final TextView time; public final ImageView isnew; public final TextView username; public final TextView department; public final ImageView enter; public final CircleImageView avatar; public final RelativeLayout listcontent; public final View root; public ViewHolder(View root) { time = (TextView) root.findViewById(R.id.time); isnew = (ImageView) root.findViewById(R.id.is_new); username = (TextView) root.findViewById(R.id.username); department = (TextView) root.findViewById(R.id.department); enter = (ImageView) root.findViewById(R.id.enter); avatar = (CircleImageView) root.findViewById(R.id.avatar); listcontent = (RelativeLayout) root.findViewById(R.id.list_content); this.root = root; } }
很方便吧?
3. Android Layout ID Converter
由于上面的插件當中我沒找到生成findView代碼的使用方法,于是我又找到了另一個插件來生成這樣的代碼。
使用方法:在你的布局文件當中右鍵,在彈出來的菜單當中選擇Convert Android layout xml,如下圖所示:
然后它會彈出一個面板,如下所示。選擇要生成的代碼的格式,按OK,這時它已經把生成的代碼復制在你的粘貼板中,然后你在使用這個布局文件的Activity或Fragment中,按Ctrl + V 把代碼粘貼出來就可以了。
4. SelectorChapek for Android
這是用于生成Selector的插件。你需要在drawable文件夾中右鍵,在彈出的菜單中選擇Generate Android Selectors,如下所示,它就會根據你的幾個drawable文件夾里的資源的命名,幫你生成Selector代碼。當然,你的資源文件需要根據約定的后綴來命名。比如按下狀態為_pressed,正常狀態為_normal,不可用狀態為_disable,等等。更詳細的說明可以看Github上該項目的說明文件,項目地址為:https://github.com/inmite/android-selector-chapek。
5. Sexy Editor
這個可是本文的壓軸插件,給你們看一下效果:
感覺碼代碼頓時有了滿滿的激情有木有!安裝之后會在設置面板的Other Settings多出一個Sexy Editor,其它使用方法不多說,看官方說明或自己摸索。相信在此圖激勵下,你們很快就會學會怎么用的。
注意:本插件有一個副作用,就是開久了會卡,甚至死掉。筆者臺式機,8G內存(永久區只設了三四百M吧),在經常切換打開文件的情況下,會越來越卡,半天時間就可能OOM了。不用這個插件的時候,還沒遇到過讓IDE OOM的情況。所以自己權衡吧。
以上插件已全部傳到CSDN資源上了,地址為:http://download.csdn.net/detail/maosidiaoxian/8583491