[英]Previous activity visible under the new fragment
當我從活動中調用片段然后片段調用成功但先前活動的某些部分位於片段的頂部時,任何人都可以幫助更正代碼
package com.example.newproject;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import static android.view.View.GONE;
public class ThankYouPageActivity extends AppCompatActivity {
Button thank_continue_btn,thank_track_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_thank_you_page);
getSupportActionBar().setTitle("Confirmation");
thank_continue_btn = findViewById(R.id.thank_continue_btn);
thank_track_btn = findViewById(R.id.thank_track_btn);
findViewById(R.id.thank_continue_btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentManager fm = getSupportFragmentManager();
HomeFragment fragment = new HomeFragment();
fm.beginTransaction().replace(R.id.thanku_container, fragment).addToBackStack(null).commit();
在片段的 xml 的根標記中將背景設置為白色
background = "#FFFFFF"
Fragment 的容器必須與 Activity 布局重疊。 請附上您的活動和片段的布局,以便我可以幫助您找到您的問題。
我有同樣的問題,我通過在 oncreateview 中設置新片段時刪除以前的片段來修復它
容器.removeAllViews(); 在替換片段之前
R.id.thanku_container
- 我認為是FrameLayout
?
使其成為完整的 match_parent。 或者像活動一樣設置背景顏色。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.