gpt4 book ai didi

android - 在新 fragment 问题下可见以前的 fragment

转载 作者:太空狗 更新时间:2023-10-29 13:52:53 25 4
gpt4 key购买 nike

我创建了带抽屉导航的 android 应用程序,当我从抽屉导航中单击项目时,旧 fragment 没有被替换,我仍然可以在新 fragment 下看到旧 fragment 。如何解决这个问题?

private void displaySelectedScreen(int id)
{
Fragment fragment = null;

switch (id)
{
case R.id.home:
fragment = new Main();
break;
case R.id.settings:
Intent intent = new Intent(this, Settings.class);
startActivity(intent);
break;
case R.id.about:
Intent intent1 = new Intent(this, About.class);
startActivity(intent1);
break;
case R.id.share:
try
{
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "Audiophileradio");
String sAux = "\nLet me recommend you this application\n\n";
sAux = sAux + "https://play.google.com/store/apps/details?id=Orion.Soft \n\n";
i.putExtra(Intent.EXTRA_TEXT, sAux);
startActivity(Intent.createChooser(i, "choose one"));
}
catch(Exception e)
{
//e.toString();
}
break;
case R.id.send:
fragment = new Feedback();
break;
}
if (fragment != null)
{
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.contentFrame, fragment).commit();
}

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item)
{
// Handle navigation view item clicks here.
int id = item.getItemId();

displaySelectedScreen(id);

return true;
}

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="audiophileradio.example.com.audiophileradio.MainActivity"
tools:showIn="@layout/app_bar_main"
android:background="@drawable/backg1">

<FrameLayout
android:id="@+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>

<TextView
android:id="@+id/textView3"
android:layout_width="13dp"
android:layout_height="21dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="+"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.977"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.13"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"/>

Image

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_height="match_parent">

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Title :"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.103"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.081"/>

<EditText
android:id="@+id/editText"
android:layout_width="218dp"
android:layout_height="35dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.593"
app:layout_constraintVertical_bias="0.084"
android:background="@drawable/border"/>

enter image description here

最佳答案

您可以为 fragment 或 contentFrame 添加背景:

<FrameLayout
android:id="@+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">

关于android - 在新 fragment 问题下可见以前的 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43808912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com