使用片段活动创建的ADT空白活动 [英] ADT blank activity created with fragment activity
问题描述
我现在真的很困惑,因为每当我创建一个空白活动的新Android应用程序时,它总会带有fragment_main.xml.我只想创建一个没有片段的空白活动.
I am really confused right now because whenever I create a new Android app with blank activity it always comes out with fragment_main.xml. I just wanted to create a blank activity without the fragment one.
在第一张图片中,空白活动带有片段布局:
In the first image the blank activity comes with the fragment layout:
第二张图片显示了创建的fragment_main
The second image shows the created fragment_main
现在我真的很困惑……这仅是在将ADT更新到最新版本之后发生的.我已提到此线程: Adt没有不要创建默认的hello world,但命令行可以 _
Now I am really confused... this only happened after updating ADT to the latest version. I have referred to this thread: Adt doesn't create default hello world but command line does_
我只是想制作一个活动空白且没有片段视图的Android应用.
I just wanted to make an Android app with blank activity with no fragment view.
推荐答案
对于那些想要有关如何从项目中删除片段的说明的人:
For those who would like instructions on how to remove Fragments from the project:
1)复制res/layout/fragment_main.xml的所有内容.打开activity_main.xml,删除FrameLayout,然后粘贴复制的内容.
1) Copy all the contents of res/layout/fragment_main.xml. Open activity_main.xml, delete the FrameLayout, and paste in the copied contents.
2)删除fragment_main.xml
2) Delete fragment_main.xml
3)在MainActivity.java中,删除整个PlaceHolderFragment类:
3) In MainActivity.java, delete the whole PlaceHolderFragment class:
/**
* A placeholder fragment containing a simple view.
*/
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;
}
}
4)从onCreate()中删除以下行:
4) Delete the following lines from onCreate():
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
这时您应该已经准备好运行项目.
At this point you should be all set to run the project.
这篇关于使用片段活动创建的ADT空白活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!