当前位置: 首页 > 工具软件 > Android-Next > 使用案例 >

Android - AndroidStudio自定义代码模板

百里泓
2023-12-01
转载请注明出处:https://blog.csdn.net/mythmayor/article/details/72844449

以下是自定义的代码模板

设置自定义代码模板方式:

1.来到设置界面(ctrl + alt + s)
2.搜索Live Templates,找到"Editor"下面的"Live Templates"
3.点击界面右侧的"+"按钮,选择"2.Templates Group..."
4.创建自定义的模板组(Java_My)
5.点击界面右侧的"+"按钮,选择"1.Live Template",编辑即可
6.编辑完成后点击界面下方红色字体后的"Define",选择应用到的地方,一般选择"Java"就可以了
7.$变量名$,在定义时,两个$符之间的是变量名,点击右侧"Edit variables"来编辑变量名所代表的意义
注意:如果未完成第6步,第7步在选择变量名属性时是没有值的。

自定义代码模板:

1.Abbreviation: catch Description: Generate catch

catch ($Exception$ $Exception_Variable_Name$) {
	$Catch$
}
$Next$

2.Abbreviation: else Description: Generate else

else {
	$Else$
}

3.Abbreviation: elseif Description: Generate elseif

else if ($Condition$) {
	$Elseif$
}

4.Abbreviation: finally Description: Generate finally

finally {
	$Finally$
}

5.Abbreviation: fore Description: Generate fore

for ($iterable_type$ $iterable_element$ : $iterable$) {
	$foreach$
}
	

6.Abbreviation: fori Description: Generate fori

for(int $INDEX$ = 0, $SIZE$ = $LIMIT$; $INDEX$ < $SIZE$; $INDEX$++) {
  $END$
}

7.Abbreviation: if Description: Generate if

if($Condition$) {
	$If$      
}

8.Abbreviation: ifelse Description: Generate ifelse

if($Condition$) {
    $Statement$
} else {
    $Statement$
}

9.Abbreviation: main Description: Generate main

public static void main(String[] args) {
	$Main$
}

10.Abbreviation: mylogd Description: Generate mylogd

android.util.Log.d("❤驭霖·骏泊☆Myth.Mayor❤", "$CLASS_NAME$ - $METHOD_NAME$: " + $content$);

11.Abbreviation: myloge Description: Generate myloge

android.util.Log.e("❤驭霖·骏泊☆Myth.Mayor❤", "$CLASS_NAME$ - $METHOD_NAME$: " + $content$);

12.Abbreviation: mylogi Description: Generate mylogi

android.util.Log.i("❤驭霖·骏泊☆Myth.Mayor❤", "$CLASS_NAME$ - $METHOD_NAME$: " + $content$);

13.Abbreviation: note Description: Generate /** */

/** $Note$ */
$Next$

14.Abbreviation: switch Description: Generate switch

switch($Condition$) {
	case $Case1$:
			$Text1$
			break;
	case $Case2$:
			$Text2$
			break;
	default :
			$Text3$
			break;
}

15.Abbreviation: syso Description: Generate syso

System.out.println($Word_Selection$);
$Next$

16.Abbreviation: try Description: Generate try

try{
	$Try$
} catch(Exception e) {
	e.printStackTrace();
}
$Next$
	

17.Abbreviation: while Description: Generate while

while($Condition$) {
	$Statement$
}
 类似资料: