使用片段活动创建的 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_
我只是想制作一个没有片段视图的空白 Activity 的 Android 应用.
I just wanted to make an Android app with blank activity with no fragment view.
推荐答案
对于那些想了解如何从项目中删除 Fragment 的人:
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屋!