码迷,mamicode.com
首页 > 移动开发 > 详细

修改Eclipse中Android项目默认模板

时间:2015-03-10 22:58:20      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:

修改Android新建项目Java代码模板

  1. 进入%ANDROIDHOME%\tools\templates\activities\BlankActivity\root\src\apppackage
  2. 复制SimpleActivity.java.ftl保存一份
  3. 打开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 }
  4. 删除无用的两个import语句

    1 import android.view.Menu;
    2 import android.view.MenuItem;
  5. 重启Eclipse,新建Android项目,之前每次都要手动删除的代码就不见啦~

修改Android项目的默认布局文件

  1. 进入%ANDROID_HOME%\tools\templates\activities\BlankActivity\root\res\layout
  2. 复制activity_simple.xml.ftl保存一份
  3. 打开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>
  4. 重启Eclipse,新建Android项目,以后新建项目就不用每次都手动修改布局了

修改Eclipse中Android项目默认模板

标签:

原文地址:http://www.cnblogs.com/WangKangReg/p/4328422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!