我现在真的很困惑,因为每当我创建一个新的带有空白活动的安卓应用程序时,它总是带着fragment_main.xml出来。我只想创建一个没有片段的空活动。
在第一张图片中,空白活动带有片段布局:
第二个图像显示了创建的fragment_main
现在我真的很困惑..。只有在将ADT更新到最新版本后才会出现这种情况。我引用了这个帖子:Adt doesn't create default hello world but command line does_
我只想做一个没有片段视图的空白活动的Android应用程序。
发布于 2014-03-18 14:25:12
对于那些想要了解如何从项目中删除片段的人:
1)复制res/layout/fragment_main.xml的所有内容。打开activity_main.xml,删除FrameLayout,然后粘贴复制的内容。
2)删除fragment_main.xml
3)在MainActivity.java中,删除整个PlaceHolderFragment类:
/**
* 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()中删除以下行:
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
此时,您应该已经做好了运行项目的所有准备。
发布于 2014-03-27 10:05:45
您可以通过编辑Android SDK文件夹中的模板文件来使用之前的模板。但是,确保你有一个"BlankActivity“文件夹的备份。
转到/templates/tools/templates/activities/BlankActivity
并将constraints
更改为constraints="empty"
。
<instantiate from="res/layout/fragment_simple.xml.ftl" to="${escapeXmlAttribute(resOut)}/layout/${fragmentLayoutName}.xml" />
并注释整行。在root/src/app_package中找到
root/res/layout.中的<#include "include_options_menu.java.ftl"> <#include "include_fragment.java.ftl">
现在,当您尝试创建新活动时,您将看到此屏幕
可以将Fragment Layout Name字段留空。
在空白活动的情况下,这对我来说很好。我不确定这是否是正确的方法,丢弃碎片和所有东西,但这对我来说是有效的。
发布于 2014-03-11 07:31:08
这是ADT版本22.6.0的一个新特性:http://developer.android.com/tools/sdk/eclipse-adt.html
编辑活动:在最新的更新中,有一个名为"Empty Activity“的新模板,它没有任何片段。这是一个扩展Activity
的普通类(即使没有默认菜单)。
注意,还有一个"Blank Activity“,它扩展了ActionBarActivity
并包含片段
https://stackoverflow.com/questions/22289164
复制