현재 시작과 같이 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 페이지 :
<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를 같이 위의 코드를 추가 할 수 있습니다. 당신의 Deveopment와 행운을 빌어 요! –