Skip to content

Commit

Permalink
跳转到其他Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
ljr7822 committed Nov 1, 2020
1 parent 41d56c2 commit 9eb4ce2
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AgreementActivity">

</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.iwen.jetpacknavigation

import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity

/**
* author : Iwen大大怪
* create : 2020/11/1 23:43
*/
class AgreementActivity: AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_agreement)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.iwen.jetpacknavigation.fragment

import android.view.View
import androidx.navigation.fragment.findNavController
import com.example.iwen.jetpacknavigation.R
import com.example.iwen.jetpacknavigation.base.BaseFragment
import kotlinx.android.synthetic.main.fragment_login.view.*

/**
* 登录的Fragment
Expand All @@ -12,4 +15,23 @@ class LoginFragment: BaseFragment() {
override fun getLayoutResId(): Int {
return R.layout.fragment_login
}

override fun initView(rootView: View) {
super.initView(rootView)
rootView.toRegisterPage.setOnClickListener {
// 跳转到注册界面
findNavController().navigate(R.id.to_register_fragment)
}

rootView.toForgetPage.setOnClickListener {
// 跳转到找回密码界面
findNavController().navigate(R.id.to_forget_fragment)
}

rootView.toAgreementPage.setOnClickListener {
// 跳转到找回密码界面
findNavController().navigate(R.id.to_agreement_page)
}

}
}
13 changes: 13 additions & 0 deletions app/src/main/res/layout/activity_agreement.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户协议" />

</LinearLayout>
18 changes: 18 additions & 0 deletions app/src/main/res/layout/fragment_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,22 @@
android:layout_height="wrap_content"
android:text="登录界面" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转到注册界面"
android:id="@+id/toRegisterPage"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转到找回密码界面"
android:id="@+id/toForgetPage"/>

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="跳转到用户协议界面"
android:id="@+id/toAgreementPage"/>

</LinearLayout>
15 changes: 15 additions & 0 deletions app/src/main/res/navigation/nav_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
android:id="@+id/login_fragment"
android:name="com.example.iwen.jetpacknavigation.fragment.LoginFragment">

<action
android:id="@+id/to_register_fragment"
app:destination="@id/register_fragment" />

<action
android:id="@+id/to_forget_fragment"
app:destination="@id/forget_fragment" />

<action android:id="@+id/to_agreement_page"
app:destination="@id/agreement_activity"/>

</fragment>

<fragment
Expand All @@ -24,4 +35,8 @@

</fragment>

<activity
android:id="@+id/agreement_activity"
android:name="com.example.iwen.jetpacknavigation.AgreementActivity" />

</navigation>

0 comments on commit 9eb4ce2

Please sign in to comment.