为什么在删除Android Android studio布局中的按钮后,仍然可以看到它?

问题描述 投票:0回答:1

我从布局中删除了signUp按钮,android studio看不到它,但是当应用程序启动时,它出现。

<?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的类代码。在将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()
    }
}

[<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS94VTA1bC5wbmcifQ==” alt =“在此处输入图像描述”>]

[<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS91VUtpeC5wbmcifQ==” alt =“在此处输入图像描述”>]

[<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9TRHphTC5wbmcifQ==” alt =“在此处输入图像描述”>]

android android-studio android-layout android-button
1个回答
0
投票

最快的解决方案

尝试使用Android Studio上的运行或调试图标在模拟器上重新启动应用。

更清洁的解决方案

  1. 从模拟器中删除应用程序。
  2. 删除app/build/outputs/apk/debug/app-debug.apk中创建的apk文件>
  3. 通常在以下两种情况下都会发生此问题

  1. 不重新运行应用程序时,仅更改布局
  2. 当您使用“即时运行”时,有时可能无法立即重新渲染,这需要几秒钟。
© www.soinside.com 2019 - 2024. All rights reserved.