新版安装SDK文件一开始有两个XML文件,activity_main.xml和fragment_main.xml,
不习惯的可以这样处理:
1.删除fragment_main.xml整个文件
2.对activity_main.xml,删除里面的内容。然后切换到Graphy Layout,放入一个LinearLayout就可以
3.对MainActivity.java,可以删除下面红色标注的内容,再把MainActivity extends ActionBarActivity 改为MainActivity extends Activity :
package com.zmcorp.weightcalculator;
import android.app.Activity //新加这一句
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManage r().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
一种最完全的改造方法就是:把两个XML文件都删除掉,还有默认的JAVA文件也删除掉,自己重新新建个main.xml文件和MainActivity.java的文件。
另外一种方法就是:创建Project不创建Activity,即不要勾选create activity,自己再创建xml和java