这是我在Google Play中发布的第一个应用。我在该项目中使用MVVM体系结构。我正在使用Android JETPACK的NAVIGATION。因此,我有一项活动,而其他活动则是碎片。当我使用android studio运行我的应用程序时,它在工具栏中显示后退按钮,但是当我从播放商店下载我的应用程序时,它不显示后退按钮。其工作方式类似于后退按钮,但不存在后退按钮图标。我不知道它为什么会发生。
这是使用的代码 活动
class SchoolDiaryMainActivity : AppCompatActivity() {
private var drawerLayout: DrawerLayout? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_school_diary_main)
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)
val host: NavHostFragment =
supportFragmentManager
.findFragmentById(R.id.my_nav_host_fragment) as NavHostFragment? ?: return
val navController = host.navController
setupActionBar(navController)
setupNavigationMenu(navController)
}
private fun setupActionBar(navController: NavController) {
drawerLayout = findViewById(R.id.drawer_layout)
NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout)
}
private fun setupNavigationMenu(navController: NavController) {
findViewById<NavigationView>(R.id.nav_view)?.let { navigationView ->
NavigationUI.setupWithNavController(navigationView, navController)
}
}
override fun onSupportNavigateUp(): Boolean {
return NavigationUI.navigateUp(
drawerLayout,
Navigation.findNavController(this, R.id.my_nav_host_fragment)
)
onBackPressed()
return true
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val retValue = super.onCreateOptionsMenu(menu)
menuInflater.inflate(R.menu.menu_empty, menu)
return retValue
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return NavigationUI.onNavDestinationSelected(
item,
Navigation.findNavController(this, R.id.my_nav_host_fragment)
)
|| super.onOptionsItemSelected(item)
}
}
// activity_school_diary_main
<androidx.drawerlayout.widget.DrawerLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
tools:context=".activities.SchoolDiaryMainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:titleTextAppearance="@style/Toolbar.TitleText"/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/my_nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
app:navGraph="@navigation/nav_graph"
app:defaultNavHost="true"/>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start|left"
app:menu="@menu/menu_nav_drawer"/>
</androidx.drawerlayout.widget.DrawerLayout>
我已将nav_graph的某些部分用作连接片段,这是android jetpack导航规则的一部分
<?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/diaryMainFrag">
<fragment android:id="@+id/testFragmentOne" android:name="amit.diary.studentdiaryentryTwo.fragments.TestFragmentOne"
android:label="af_test_one" tools:layout="@layout/af_test_one"/>
<fragment android:id="@+id/diaryMainFrag" android:name="amit.diary.studentdiaryentryTwo.fragments.DiaryMainFrag"
android:label="af_diary_main" tools:layout="@layout/af_diary_main">
<action android:id="@+id/action_diaryMainFrag_to_homeworkFrag" app:destination="@id/homeworkFrag"/>
答案 0 :(得分:2)
按照Navigation 1.0.0-beta01 release notes:
解决了将ProGuard与混淆一起使用时NavigationUI处理后退箭头不会出现的问题。 b/123449431
因此,请升级到最新版本-当前为justifyContent
。