修改Android新建项目Java代码模板
- 进入%ANDROIDHOME%\tools\templates\activities\BlankActivity\root\src\apppackage
- 复制SimpleActivity.java.ftl保存一份
-
打开SimpleActivity.java.ftl,删除下列代码
1 @Override 2 public boolean onCreateOptionsMenu(Menu menu) { 3 // Inflate the menu; this adds items to the action bar if it is present. 4 getMenuInflater().inflate(R.menu.${menuName}, menu); 5 return true; 6 } 7 8 @Override 9 public boolean onOptionsItemSelected(MenuItem item) { 10 // Handle action bar item clicks here. The action bar will 11 // automatically handle clicks on the Home/Up button, so long 12 // as you specify a parent activity in AndroidManifest.xml. 13 int id = item.getItemId(); 14 if (id == R.id.action_settings) { 15 return true; 16 } 17 return super.onOptionsItemSelected(item); 18 }
-
删除无用的两个import语句
1 import android.view.Menu; 2 import android.view.MenuItem;
- 重启Eclipse,新建Android项目,之前每次都要手动删除的代码就不见啦~
修改Android项目的默认布局文件
- 进入%ANDROID_HOME%\tools\templates\activities\BlankActivity\root\res\layout
- 复制activity_simple.xml.ftl保存一份
-
打开activity_simple.xml.ftl,替换成下列代码
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical"> 6 7 <TextView 8 android:text="@string/hello_world" 9 android:layout_width="wrap_content" 10 android:layout_height="wrap_content" /> 11 12 </LinearLayout>
- 重启Eclipse,新建Android项目,以后新建项目就不用每次都手动修改布局了