为什么AndroidAndroid工作室版面中的按钮删除后,还能看到?
Why, after deleting the button in the Android Android studio’s layout, does it still see it?
我从我的布局中删除了注册按钮,android工作室看不到它,但当应用程序启动时,它出现了。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:backgroundTint="@color/colorPrimaryDark"
android:layout_height="match_parent"
tools:context=".home.MainActivity">
<FrameLayout
android:id="@+id/nav_host_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/roundLayout"/>
<com.github.florent37.shapeofview.shapes.RoundRectView
android:id="@+id/roundLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:elevation="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:shape_roundRect_bottomLeftRadius="22dp"
app:shape_roundRect_bottomRightRadius="22dp"
app:shape_roundRect_topLeftRadius="8dp"
app:shape_roundRect_topRightRadius="8dp">
<com.ismaeldivita.chipnavigation.ChipNavigationBar
android:id="@+id/chipNavigationMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/white"
app:cnb_menuResource="@menu/bottom_menu"/>
</com.github.florent37.shapeofview.shapes.RoundRectView>
</androidx.constraintlayout.widget.ConstraintLayout>
这是调用 activity_home 的 class 代码。我将activity_home代码转移到另一个布局后,它起作用了,但立即又挂了,没有改变。
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.PersistableBundle
import androidx.fragment.app.Fragment
import cheprasov.egor.cchat.R
import cheprasov.egor.cchat.fragments.favorite.favorites
import cheprasov.egor.cchat.fragments.home.homeFragment
import cheprasov.egor.cchat.fragments.settings.settings
import com.google.firebase.auth.FirebaseAuth
import com.ismaeldivita.chipnavigation.ChipNavigationBar
class MainActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
private lateinit var mAthListner: FirebaseAuth.AuthStateListener
private lateinit var menu: ChipNavigationBar
private var fragment: Fragment? = null
private lateinit var fragmentsHome: Fragment
private lateinit var fragments: Fragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
init()
if(fragment== null){
val transaction = supportFragmentManager.beginTransaction()
fragmentsHome = homeFragment()
transaction.replace(R.id.nav_host_fragment,fragmentsHome)
transaction.commit()
}
menu.setOnItemSelectedListener { id ->
val option = when (id){
R.id.home -> {
fragments = fragmentsHome
setFragment(fragments)
}
R.id.favorited -> {
fragments = favorites()
setFragment(fragments)
}
R.id.settings ->{
fragments = settings()
setFragment(fragments)
}
else -> finish()
}
}
}
private fun setFragment(fragment: Fragment){
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.nav_host_fragment,fragment)
transaction.commit()
}
private fun init(){
auth = FirebaseAuth.getInstance()
menu = findViewById(R.id.chipNavigationMenu)
}
override fun onStop() {
super.onStop()
}
override fun onPause() {
super.onPause()
}
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
}
override fun onResume() {
super.onResume()
}
override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
super.onSaveInstanceState(outState, outPersistentState)
}
override fun onBackPressed() {
super.onBackPressed()
moveTaskToBack(true)
}
private fun signOut(){
auth.signOut()
}
}
[]
[]
[]
最快的解决方案
尝试使用 运行 或 Android Studio 上的调试图标在模拟器上重新启动应用程序。
更清洁的解决方案
- 从模拟器中删除应用程序。
- 删除
app/build/outputs/apk/debug/app-debug.apk
中创建的 apk 文件
一般有以下两种情况会出现此问题
- App不重新运行时,只改变布局
- 当您使用 Instant 运行 时,有时它可能不会立即重新呈现,需要几秒钟..
我从我的布局中删除了注册按钮,android工作室看不到它,但当应用程序启动时,它出现了。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:backgroundTint="@color/colorPrimaryDark"
android:layout_height="match_parent"
tools:context=".home.MainActivity">
<FrameLayout
android:id="@+id/nav_host_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/roundLayout"/>
<com.github.florent37.shapeofview.shapes.RoundRectView
android:id="@+id/roundLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:elevation="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:shape_roundRect_bottomLeftRadius="22dp"
app:shape_roundRect_bottomRightRadius="22dp"
app:shape_roundRect_topLeftRadius="8dp"
app:shape_roundRect_topRightRadius="8dp">
<com.ismaeldivita.chipnavigation.ChipNavigationBar
android:id="@+id/chipNavigationMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/white"
app:cnb_menuResource="@menu/bottom_menu"/>
</com.github.florent37.shapeofview.shapes.RoundRectView>
</androidx.constraintlayout.widget.ConstraintLayout>
这是调用 activity_home 的 class 代码。我将activity_home代码转移到另一个布局后,它起作用了,但立即又挂了,没有改变。
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.PersistableBundle
import androidx.fragment.app.Fragment
import cheprasov.egor.cchat.R
import cheprasov.egor.cchat.fragments.favorite.favorites
import cheprasov.egor.cchat.fragments.home.homeFragment
import cheprasov.egor.cchat.fragments.settings.settings
import com.google.firebase.auth.FirebaseAuth
import com.ismaeldivita.chipnavigation.ChipNavigationBar
class MainActivity : AppCompatActivity() {
private lateinit var auth: FirebaseAuth
private lateinit var mAthListner: FirebaseAuth.AuthStateListener
private lateinit var menu: ChipNavigationBar
private var fragment: Fragment? = null
private lateinit var fragmentsHome: Fragment
private lateinit var fragments: Fragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
init()
if(fragment== null){
val transaction = supportFragmentManager.beginTransaction()
fragmentsHome = homeFragment()
transaction.replace(R.id.nav_host_fragment,fragmentsHome)
transaction.commit()
}
menu.setOnItemSelectedListener { id ->
val option = when (id){
R.id.home -> {
fragments = fragmentsHome
setFragment(fragments)
}
R.id.favorited -> {
fragments = favorites()
setFragment(fragments)
}
R.id.settings ->{
fragments = settings()
setFragment(fragments)
}
else -> finish()
}
}
}
private fun setFragment(fragment: Fragment){
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.nav_host_fragment,fragment)
transaction.commit()
}
private fun init(){
auth = FirebaseAuth.getInstance()
menu = findViewById(R.id.chipNavigationMenu)
}
override fun onStop() {
super.onStop()
}
override fun onPause() {
super.onPause()
}
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
}
override fun onResume() {
super.onResume()
}
override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
super.onSaveInstanceState(outState, outPersistentState)
}
override fun onBackPressed() {
super.onBackPressed()
moveTaskToBack(true)
}
private fun signOut(){
auth.signOut()
}
}
[
[
[
最快的解决方案
尝试使用 运行 或 Android Studio 上的调试图标在模拟器上重新启动应用程序。
更清洁的解决方案
- 从模拟器中删除应用程序。
- 删除
app/build/outputs/apk/debug/app-debug.apk
中创建的 apk 文件
一般有以下两种情况会出现此问题
- App不重新运行时,只改变布局
- 当您使用 Instant 运行 时,有时它可能不会立即重新呈现,需要几秒钟..