布局会产生所有白色内容

时间:2018-01-05 00:50:08

标签: android android-constraintlayout

为什么我的所有内容都是白色的?当我使用代码更新它正确显示的字符串,但在此之前没有任何正确显示。它在android studio设计视图中看起来很好。

All white buttons

<?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"
    tools:context="com.tomasforsman.snookerscore.MainActivity">

    <TextView
        android:id="@+id/textP1Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:textColor="@android:color/black"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="@string/player1" />

    <TextView
        android:id="@+id/textP2Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="16dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="@string/player2" />

    <ImageButton
        android:id="@+id/imageP1"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_marginTop="12dp"
        android:contentDescription="@string/player1_img_desc"
        app:layout_constraintEnd_toEndOf="@+id/textP1Name"
        app:layout_constraintStart_toStartOf="@+id/textP1Name"
        app:layout_constraintTop_toBottomOf="@+id/textP1Name"
        app:srcCompat="@drawable/male_user" />

    <ImageButton
        android:id="@+id/imageP2"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:layout_marginTop="8dp"
        android:contentDescription="@string/player2_img_desc"
        app:layout_constraintEnd_toEndOf="@+id/textP2Name"
        app:layout_constraintStart_toStartOf="@+id/textP2Name"
        app:layout_constraintTop_toBottomOf="@+id/textP2Name"
        app:srcCompat="@drawable/male_user" />

    <Button
        android:id="@+id/buttonBlue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="@string/blue" />

    <Button
        android:id="@+id/buttonPink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonBlue"
        tools:text="@string/pink" />

    <Button
        android:id="@+id/buttonRed"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonPink"
        tools:text="@string/red" />

    <Button
        android:id="@+id/buttonBlack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonRed"
        tools:text="@string/black" />

    <Button
        android:id="@+id/buttonYellow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/buttonBrown"
        app:layout_constraintEnd_toStartOf="@+id/buttonBrown"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/buttonBrown"
        tools:text="@string/yello" />

    <Button
        android:id="@+id/buttonBrown"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toTopOf="@+id/buttonBlue"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageP1"
        tools:text="@string/brown" />

    <Button
        android:id="@+id/buttonGreen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/buttonBrown"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/buttonBrown"
        app:layout_constraintTop_toTopOf="@+id/buttonBrown"
        tools:text="@string/green" />

    <TextView
        android:id="@+id/textP1ScoreTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toStartOf="@+id/textP2ScoreTitle"
        app:layout_constraintStart_toEndOf="@+id/textP1Name"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="@string/score" />

    <TextView
        android:id="@+id/textP2ScoreTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toStartOf="@+id/textP2Name"
        app:layout_constraintStart_toEndOf="@+id/textP1ScoreTitle"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="@string/score" />

    <TextView
        android:id="@+id/textP1Score"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="@+id/textP1ScoreTitle"
        app:layout_constraintStart_toStartOf="@+id/textP1ScoreTitle"
        app:layout_constraintTop_toBottomOf="@+id/textP1ScoreTitle"
        tools:text="@string/text_p1_score" />

    <TextView
        android:id="@+id/textP2Score"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        app:layout_constraintEnd_toEndOf="@+id/textP2ScoreTitle"
        app:layout_constraintStart_toStartOf="@+id/textP2ScoreTitle"
        app:layout_constraintTop_toBottomOf="@+id/textP2ScoreTitle"
        tools:text="@string/text_p2_score" />

    <TextView
        android:id="@+id/textBreakTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/buttonBlue"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@+id/buttonBlue"
        tools:text="@string/break_score" />

    <TextView
        android:id="@+id/textBreak"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toEndOf="@+id/textBreakTitle"
        app:layout_constraintTop_toTopOf="parent"
        tools:text="@string/text_break" />

    <TextView
        android:id="@+id/textLeftOnTableTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        app:layout_constraintBottom_toTopOf="@+id/buttonPink"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/buttonBlue"
        tools:text="@string/left_on_table" />

    <TextView
        android:id="@+id/textLeftOnTable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/textLeftOnTableTitle"
        app:layout_constraintStart_toEndOf="@+id/textLeftOnTableTitle"
        app:layout_constraintTop_toTopOf="@+id/textLeftOnTableTitle"
        tools:text="@string/text_left_on_table" />

    <TextView
        android:id="@+id/textRedOnTableTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        app:layout_constraintBottom_toBottomOf="@+id/buttonRed"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@+id/buttonRed"
        tools:text="@string/red_on_table" />

    <TextView
        android:id="@+id/textRedOnTable"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/textRedOnTableTitle"
        app:layout_constraintStart_toEndOf="@+id/textRedOnTableTitle"
        app:layout_constraintTop_toTopOf="@+id/textRedOnTableTitle"
        tools:text="15" />

</android.support.constraint.ConstraintLayout>

我已经尝试清理代码并重新构建它并尝试在不同版本的android studio中使用新项目。我确信我会错过一些简单但又无法弄清楚的东西。

字符串xml文件:

<resources>
    <string name="app_name">Snooker Score</string>
    <string name="red">Red</string>
    <string name="black">Black</string>
    <string name="pink">Pink</string>
    <string name="blue">Blue</string>
    <string name="yello">Yellow</string>
    <string name="brown">Brown</string>
    <string name="green">Green</string>
    <string name="score">Score</string>
    <string name="break_score">Break:</string>
    <string name="left_on_table">Left on table:</string>
    <string name="red_on_table">Red on table:</string>
    <string name="player1">Player 1</string>
    <string name="player2">Player 2</string>
    <string name="player1_img_desc">Player 1 description.</string>
    <string name="player2_img_desc">Player 2 description.</string>
    <string name="text_p1_score">155</string>
    <string name="text_p2_score">155</string>
    <string name="text_break">155</string>
    <string name="text_left_on_table">155</string>
</resources>

2 个答案:

答案 0 :(得分:3)

使用:

android:text="@string/your_string_name"

请勿使用

tools:text="@string/your_string_name"

答案 1 :(得分:0)

在设备上运行时,所有带有tools:的XML属性都会从XML中删除。

您使用了错误的属性

另外,你提到&#34;白色内容&#34; ...我不知道如何放置文字会改变按钮的颜色。这就是它上面写的内容。

我认为您要么使用ImageButton要么设置背景,而不是文本