我是 Android 新手,目前正在学习。我遇到了与 android-fragments 相关的问题,我编写了代码,但它什么也没做!仅显示片段颜色。当我尝试去除片段的颜色时,它成功了!我无法纠正这个问题。请帮忙!XML -activity_main.xml<?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:layout_height="match_parent" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="113dp" android:layout_height="50dp" android:text="Switch1" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.945" /> <fragment android:id="@+id/fragment" android:name="com.example.fragments.Color_Purple" android:layout_width="390dp" android:layout_height="385dp" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" app:layout_constraintBottom_toTopOf="@+id/button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.68" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.137" /></androidx.constraintlayout.widget.ConstraintLayout>XML - 片段代码<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Color_Purple"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:background="#C403FA" /></FrameLayout>
1 回答
明月笑刀无情
TA贡献1828条经验 获得超4个赞
只是改变 :
Boolean flag = true;
到
boolean flag = true;
并android:background="#C403FA"从您的TextView:
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C403FA" //remove this line
/>
添加回答
举报
0/150
提交
取消