我有一个android studio项目,并且只有很少的布局与它们的.java文件相关联
注意:“由于声誉低下,我无法发布图片”
我有:
和
Android清单是:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@drawable/blablabla"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:screenOrientation="portrait"
android:name="com.icetea09.demomaterialdesigndrawermenu.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
layout1.xml代码是这样的:“ activity_main.xml是我的layout1”
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mLvDrawerMenu = (ListView) findViewById(R.id.lv_drawer_menu);
List<DrawerMenuItem> menuItems = generateDrawerMenuItems();
mDrawerMenuAdapter = new DrawerMenuItemAdapter(getApplicationContext(), menuItems);
mLvDrawerMenu.setAdapter(mDrawerMenuAdapter);
mLvDrawerMenu.setOnItemClickListener(this);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.app_name, R.string.app_name) {
public void onDrawerClosed(View view) {
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if(savedInstanceState == null){
setFragment(0, BikeFragment.class);
}
}
默认的布局加载视图是“带有Layout1.java的layout1.xml”
问题是如何将开始视图的布局从layout1更改为layout2。就像我第一次安装该应用程序时一样,它将显示“ layout2.xml”视图,而不是默认视图(在我的情况下为layout1.xml)。
感谢您的时间。
一种方法是添加新活动。您可以单击“启动器活动”。然后,Android Studio将使这个新活动成为Launcher Activity。
当您已经添加了两个活动时,还有另一种方法。
最好的方法是使用
AndroidManifest.xml
文件。要将活动视为启动程序活动,请在清单中的活动中添加以下属性:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
这个问题可能是重复的:更改应用程序的启动活动-Android
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句