【问题标题】:Previous activity visible under the new fragment新片段下可见的先前活动
【发布时间】:2019-10-02 22:59:32
【问题描述】:

当我从活动中调用片段然后片段调用成功但先前活动的某些部分位于片段顶部时,任何人都可以帮助更正代码

包 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();

【问题讨论】:

标签: android android-fragments


【解决方案1】:

在片段的 xml 的根标记中将背景设置为白色

background = "#FFFFFF"

【讨论】:

    【解决方案2】:

    Fragment 的容器必须与 Activity 布局重叠。请附上您的 Activity 和 Fragment 的布局,以便我可以帮助您找到您的问题。

    【讨论】:

      【解决方案3】:

      我有同样的问题,我通过在 oncreateview 中设置新片段时删除以前的片段来修复它

      container.removeAllViews();在替换片段之前

      【讨论】:

      • container.removeAllViews();在我的活动中出现错误
      • 你能张贴一张图片,它显示的是什么,以前的片段内容或你有框架布局的活动内容?另外,您不要在活动中使用此代码,而是在 oncreateview 的片段类中使用此代码
      【解决方案4】:

      R.id.thanku_container - 我想是FrameLayout?

      使其完全匹配_parent。或者像活动一样设置背景颜色。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多