Android Studio實用插件

1、Gson Format
在網絡通信中,經常用到的就是訪問服務器返回一個json,Android Studio提供一個插件,可以通過Json一鍵生成Bean;
這是服務器返回的Json,通過AS的工具,Gson Format(可以在Plugins中添加),

{
    "status": true,
    "info": "信息獲取成功",
    "results": {
        "typeid": "3",
        "name": null,
        "sex": "男",
        "img": "http://a.ba-mgt.com/images/avatar/a36972e646019c7d0bc76447e72d1150.png",
        "type": "分析員"
    }
}

按住Alt+Insert,彈出這裏寫圖片描述
選擇GsonFormat,將Json粘貼到輸入框,按確定就可以生成Bean了;
這裏寫圖片描述

這是生成的Bean;

public class user {


    /**
     * status : true
     * info : 信息獲取成功
     * results : {"typeid":"3","name":null,"sex":"男","img":"http://a.ba-mgt.com/images/avatar/a36972e646019c7d0bc76447e72d1150.png","type":"分析員"}
     */

    private boolean status;
    private String info;
    /**
     * typeid : 3
     * name : null
     * sex : 男
     * img : http://a.ba-mgt.com/images/avatar/a36972e646019c7d0bc76447e72d1150.png
     * type : 分析員
     */

    private ResultsEntity results;

    public void setStatus(boolean status) {
        this.status = status;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public void setResults(ResultsEntity results) {
        this.results = results;
    }

    public boolean isStatus() {
        return status;
    }

    public String getInfo() {
        return info;
    }

    public ResultsEntity getResults() {
        return results;
    }

    public static class ResultsEntity {
        private String typeid;
        private Object name;
        private String sex;
        private String img;
        private String type;

        public void setTypeid(String typeid) {
            this.typeid = typeid;
        }

        public void setName(Object name) {
            this.name = name;
        }

        public void setSex(String sex) {
            this.sex = sex;
        }

        public void setImg(String img) {
            this.img = img;
        }

        public void setType(String type) {
            this.type = type;
        }

        public String getTypeid() {
            return typeid;
        }

        public Object getName() {
            return name;
        }

        public String getSex() {
            return sex;
        }

        public String getImg() {
            return img;
        }

        public String getType() {
            return type;
        }
    }
}

2、Android ButterKnife Zelezny
Android Studio提供一個工具,可以將一個XML中的對象一鍵注入到Fragment或Activity中
首先,要在app中添加jar這裏寫圖片描述
然後,xml中的代碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <ImageView
        android:layout_width="wrap_contentw"
        android:layout_height="wrap_content"
        android:id="@+id/img"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btn"
        />

</LinearLayout>

在activity中,按alt+insert彈出框,選中圖中的那個,就可以了
這裏寫圖片描述
生成之後的代碼:

public class user extends Activity {

    @InjectView(R.id.img)
    ImageView img;
    @InjectView(R.id.btn)
    Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        ButterKnife.inject(this);
    }
}

3、Lifecycle Sorter
可以根據Activity或者fragment的生命週期對其生命週期方法位置進行先後排序,快捷鍵Ctrl + alt + K
這裏寫圖片描述

4、Android Postfix Completion
快速編寫Toast的一個工具類:
這裏寫圖片描述
5、Android Methods Count
統計Android依賴庫中方法的總個數:
這裏寫圖片描述

發佈了61 篇原創文章 · 獲贊 72 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章