使用到的库 implementation 'androidx.navigation:navigation-fragment:2.2.2' implementation 'androidx.navigation:navigation-ui:2.2.2'master
parent
612d0fa7b8
commit
2dd545cada
@ -0,0 +1,11 @@
|
|||||||
|
package com.thankvinci.CloudKey.Fragment;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.thankvinci.CloudKey.R;
|
||||||
|
|
||||||
|
public class AboutFragment extends Fragment {
|
||||||
|
public AboutFragment(){
|
||||||
|
super(R.layout.about_fragment);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.thankvinci.CloudKey.Fragment;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.thankvinci.CloudKey.R;
|
||||||
|
|
||||||
|
public class FileManageFragment extends Fragment {
|
||||||
|
public FileManageFragment(){
|
||||||
|
super(R.layout.filemanage_fragment);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(View view,Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
}
|
||||||
|
}
|
@ -1,29 +1,43 @@
|
|||||||
package com.thankvinci.CloudKey;
|
package com.thankvinci.CloudKey;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
|
import androidx.navigation.NavController;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
|
import androidx.navigation.ui.AppBarConfiguration;
|
||||||
|
import androidx.navigation.ui.NavigationUI;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.google.android.material.navigation.NavigationView;
|
||||||
import com.thankvinci.CloudKey.NetUtils.NetHandler;
|
import com.thankvinci.CloudKey.NetUtils.NetHandler;
|
||||||
import com.thankvinci.CloudKey.NetUtils.NetThread;
|
import com.thankvinci.CloudKey.NetUtils.NetThread;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
private NavHostFragment navHostFragment;
|
||||||
|
private NavController navController;
|
||||||
|
private AppBarConfiguration appBarConfiguration;
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
//声明一个Handler
|
||||||
Handler handler = new NetHandler(this);
|
Handler handler = new NetHandler(this);
|
||||||
TextView textView = findViewById(R.id.text);
|
//加载NavGraph
|
||||||
textView.setOnClickListener(new View.OnClickListener() {
|
navHostFragment = (NavHostFragment)getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
|
||||||
@Override
|
navController = navHostFragment.getNavController();
|
||||||
public void onClick(View v) {
|
DrawerLayout drawerLayout = findViewById(R.id.drawLayout);
|
||||||
Thread t = new Thread(new NetThread(handler));
|
appBarConfiguration = new AppBarConfiguration.Builder(R.id.fileManageFragment).setDrawerLayout(drawerLayout).build();
|
||||||
t.start();
|
NavigationUI.setupActionBarWithNavController(this,navController,appBarConfiguration);
|
||||||
}
|
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||||
});
|
NavigationUI.setupWithNavController(navigationView,navController);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSupportNavigateUp() {
|
||||||
|
return NavigationUI.navigateUp(navController,appBarConfiguration)||super.onSupportNavigateUp();
|
||||||
}
|
}
|
||||||
}
|
}
|
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 42 KiB |
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:context=".Fragment.AboutFragment">
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -1,19 +1,23 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/drawLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
<androidx.fragment.app.FragmentContainerView
|
||||||
<TextView
|
android:id="@+id/nav_host_fragment"
|
||||||
|
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:defaultNavHost="true"
|
||||||
|
app:navGraph="@navigation/nav_graph"/>
|
||||||
|
<com.google.android.material.navigation.NavigationView
|
||||||
|
android:id="@+id/nav_view"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:text="Hello World!"
|
android:layout_gravity="start"
|
||||||
android:id="@+id/text"
|
android:fitsSystemWindows="true"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:menu="@menu/nav_menu"/>
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
</androidx.drawerlayout.widget.DrawerLayout>
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:context=".Fragment.FileManageFragment" >
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:id="@+id/fileManageFragment" android:title="文件"></item>
|
||||||
|
<item android:id="@+id/aboutFragment" android:title="关于我们"></item>
|
||||||
|
</menu>
|
After Width: | Height: | Size: 55 KiB |
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/nav_graph"
|
||||||
|
app:startDestination="@id/fileManageFragment">
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/fileManageFragment"
|
||||||
|
android:name="com.thankvinci.CloudKey.Fragment.FileManageFragment"
|
||||||
|
android:label="filemanagefragment"
|
||||||
|
tools:layout="@layout/filemanage_fragment" />
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/aboutFragment"
|
||||||
|
android:name="com.thankvinci.CloudKey.Fragment.AboutFragment"
|
||||||
|
android:label="about_fragment"
|
||||||
|
tools:layout="@layout/about_fragment" />
|
||||||
|
</navigation>
|
Loading…
Reference in new issue