亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法更改片段的背景顏色

無法更改片段的背景顏色

慕碼人2483693 2023-06-28 19:44:53
我是 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

        />


查看完整回答
反對 回復 2023-06-28
  • 1 回答
  • 0 關注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號