|
@@ -0,0 +1,75 @@
|
|
|
+package jx.cn.escort.ui.activity
|
|
|
+
|
|
|
+import android.content.Context
|
|
|
+import android.os.Bundle
|
|
|
+import android.view.LayoutInflater
|
|
|
+import android.view.MenuItem
|
|
|
+import android.view.View
|
|
|
+import android.view.ViewGroup
|
|
|
+import android.widget.Toast
|
|
|
+import androidx.appcompat.app.AppCompatActivity
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout
|
|
|
+import androidx.fragment.app.Fragment
|
|
|
+import androidx.fragment.app.FragmentTransaction
|
|
|
+import androidx.navigation.Navigation
|
|
|
+import com.google.android.material.navigation.NavigationView
|
|
|
+import com.xuexiang.xui.widget.actionbar.TitleBar
|
|
|
+import jx.cn.escort.R
|
|
|
+
|
|
|
+class MainActivity : AppCompatActivity() {
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
+ setContentView(R.layout.activity_main)
|
|
|
+
|
|
|
+
|
|
|
+ var layout= findViewById<View>(R.id.top_bar)
|
|
|
+ var topBarView=(layout as ViewGroup).getChildAt(0) as TitleBar
|
|
|
+ topBarView.setLeftClickListener(object:View.OnClickListener {
|
|
|
+
|
|
|
+ override fun onClick(v: View?) {
|
|
|
+ Toast.makeText(baseContext,"测试",Toast.LENGTH_SHORT).show()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ var layoutInflater=baseContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
|
|
+ var bottomNav= findViewById<NavigationView>(R.id.bottom_nav)
|
|
|
+ var navContent=findViewById<ViewGroup>(R.id.nav_content)
|
|
|
+ bottomNav.setNavigationItemSelectedListener(object:NavigationView.OnNavigationItemSelectedListener{
|
|
|
+ override fun onNavigationItemSelected(item: MenuItem): Boolean {
|
|
|
+ var id=item.itemId
|
|
|
+ when(id){
|
|
|
+ R.id.index-> {
|
|
|
+ val fragment= layoutInflater.inflate(R.layout.fragment_index,navContent) as Fragment
|
|
|
+ switchFragment(fragment)
|
|
|
+ }
|
|
|
+ R.id.tasks->{
|
|
|
+ val fragment= layoutInflater.inflate(R.layout.fragment_tasks,navContent) as Fragment
|
|
|
+ switchFragment(fragment)
|
|
|
+ }
|
|
|
+ R.id.mine->{
|
|
|
+ val fragment= layoutInflater.inflate(R.layout.fragment_mine,navContent) as Fragment
|
|
|
+ switchFragment(fragment)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private fun switchFragment(fragment:Fragment){
|
|
|
+ var fm=supportFragmentManager
|
|
|
+ var transaction: FragmentTransaction =fm.beginTransaction()
|
|
|
+ transaction.replace(R.id.nav_content,fragment)
|
|
|
+ transaction.commitAllowingStateLoss()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|