Android Studio Live模板編寫

非淡泊無以明志,非寧靜無以致遠——諸葛亮

安卓開發者有時工作很忙碌,爲了節省時間和保持充沛的精力,是時候考慮通過Android Studio工具編寫模板。

實時模板介紹,需要翻牆

1、查閱Android Studio 自帶模板

2、Android Studio 自帶模板及部分使用

Android const(Define android style int constant)使用時編碼的光標位於類的內部方法外部

模板:

private static final int $name$ = $value$;
public class TestActivity extends BaseActivity {
    private static final int  = 435;
}

IntentView(Creates an Intent with ACTION_VIEW)使用時編碼的光標位於方法內部

模板:

android.content.Intent view = new Intent();
view.setAction(Intent.ACTION_VIEW);
view.setData(android.net.Uri.parse($url$));
startActivity(view);
public void initView() {
    Intent view = new Intent();
    view.setAction(Intent.ACTION_VIEW);
    view.setData(Uri.parse());
    startActivity(view);
}

3、添加自己的模板

1、創建生命週期函數:

Abbreviation:activityLifeMethod

Description:Activity生命週期函數

Template text:

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState,
                                    @NonNull PersistableBundle outPersistentState) {
        super.onSaveInstanceState(outState, outPersistentState);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

2、添加xml佈局:

Abbreviation:tcText

Description:線性佈局標題和內容 android:orientation="horizontal"

Template text:

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            tools:text="title" />

        <TextView
            android:layout_width="0dp"
            tools:text="content"
            android:padding="10dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.0" />

   </LinearLayout>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章