修改Eclipse中Android项目默认模板

修改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项目,以后新建项目就不用每次都手动修改布局了

转载于:https://www.cnblogs.com/WangKangReg/p/4328422.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值