Added Home/Settings/About Fragment and adjust navigation

This commit is contained in:
Xcreen
2018-09-27 10:56:28 +02:00
parent 2e34c5d9e1
commit 171e2248ce
9 changed files with 135 additions and 20 deletions

View File

@@ -0,0 +1,21 @@
package net.xcreen.restsms;
import androidx.fragment.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class AboutFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_about, container, false);
}
}

View File

@@ -0,0 +1,21 @@
package net.xcreen.restsms;
import androidx.fragment.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class HomeFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
}
}

View File

@@ -7,6 +7,9 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
@@ -31,6 +34,15 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//Set Home Fragment
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
try {
Fragment homeFragment = HomeFragment.class.newInstance();
fragmentTransaction.replace(R.id.main_framelayout, homeFragment).commit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
@@ -45,24 +57,25 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
/*
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
//Set new Fragment
Fragment fragment;
switch(item.getItemId()){
case R.id.nav_home:
fragment = new HomeFragment();
break;
case R.id.nav_settings:
fragment = new SettingsFragment();
break;
case R.id.nav_about:
fragment = new AboutFragment();
break;
default:
fragment = new HomeFragment();
break;
}
*/
//Replace Fragment
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_framelayout, fragment).addToBackStack("fragBack").commit();
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}

View File

@@ -0,0 +1,21 @@
package net.xcreen.restsms;
import androidx.fragment.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class SettingsFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_settings, container, false);
}
}

View File

@@ -38,7 +38,8 @@
<FrameLayout
android:id="@+id/main_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
android:padding="@dimen/fragment_padding"/>
</LinearLayout>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AboutFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="ABOUT" />
</FrameLayout>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello Home" />
</FrameLayout>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SettingsFragment">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="SETTINGS" />
</FrameLayout>

View File

@@ -1,8 +1,7 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="nav_header_vertical_spacing">8dp</dimen>
<dimen name="nav_header_height">176dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="fragment_padding">20dp</dimen>
</resources>