現在、私は起動時にfragment_emptyを使用しています。 fragment_empty 私はfragment_homeをスタートアップページ(アプリケーションを起動するとき)にしたいが、私はすべてのページでfragment_homeを見たくない。android studioスタートアップページとしてナビゲーションアクティビティからフラグメントを設定する方法
fragment_homeページ:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welkom op home!"
android:padding="10dp"
/>
<ImageView
android:layout_width="236dp"
android:layout_height="218dp"
android:src="@mipmap/ic_launcher"
android:id="@+id/imageView2" />
fragment_emptyページ:
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
マイMainActivity(ナビゲーション引き出し):
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
Fragment fragment = null;
if (id == R.id.nav_home) {
fragment = new HomeFragment();
} else if (id == R.id.nav_evenementen) {
fragment = new EvenementenFragment();
} else if (id == R.id.nav_contact) {
fragment = new ContactFragment();
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
App_bar_mainページ:あなたのMainActivity
onCreate()
方法では代わりにreplace
の
<include layout="@layout/fragment_empty" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
おかげで私の友人 –
Npのように上記のコードを追加することができます。あなたの開発と幸運! –