CheckBox和CheckedTextView的单词未出现

时间:2019-05-21 22:43:45

标签: android android-layout android-constraintlayout android-checkbox

我制作了一个用于弹出的xml布局文件。 在布局中,我设置了两个CheckedTextViews。 我可以在预览中看到文字。 但是,当我在AVD和手机上安装并激活它时,看不到它的文本。 这是非常简单的代码。但是我不知道这是怎么回事。

我将CheckedTextView替换为CheckBox。 但这仍然行不通。

popup.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="300dp"
    android:layout_height="150dp" 
    android:background="@color/colorWhite">

    <android.support.constraint.Guideline
        android:id="@+id/guideline28"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="0dp"                                              
        app:layout_constraintGuide_percent="0.6"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline22"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="0dp"
        app:layout_constraintGuide_percent="0.2"/>

    <android.support.constraint.ConstraintLayout
        android:id="@+id/constraintLayout6"
        android:layout_marginStart="8dp" 
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline22" 
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" 
        app:layout_constraintStart_toStartOf="parent">

        <!-- this is the CheckedTextView -->
        <CheckedTextView
            android:id="@+id/checkedTextView2"
            android:text="@string/week"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceListItemSmall"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple" 
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:visibility="visible"
            app:layout_constraintTop_toTopOf="@+id/checkedTextView3"
            app:layout_constraintBottom_toBottomOf="@+id/checkedTextView3"
            app:layout_constraintEnd_toStartOf="@+id/guideline23" 
            app:layout_constraintStart_toStartOf="parent"/>

        <CheckedTextView
            android:id="@+id/checkedTextView3" 
            android:text="@string/weekend"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp" 
            android:layout_marginEnd="8dp"
            app:layout_constraintStart_toStartOf="@+id/guideline23"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <android.support.constraint.Guideline
            android:id="@+id/guideline23"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="0dp"
            app:layout_constraintGuide_percent="0.5"/>

    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content" 
        android:layout_marginEnd="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="8dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline28"
        app:layout_constraintTop_toBottomOf="@+id/constraintLayout6" android:id="@+id/constraintLayout7">

        <Button
            android:id="@+id/button16"
            android:text="@string/monday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line"
            app:layout_constraintStart_toStartOf="parent" 
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button17" 
            app:layout_constraintTop_toTopOf="@+id/button17"
            app:layout_constraintBottom_toBottomOf="@+id/button17"/>

        <Button
            android:id="@+id/button17"
            android:text="@string/tuesday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line" 
            app:layout_constraintStart_toEndOf="@+id/button16" 
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button18" 
            app:layout_constraintTop_toTopOf="@+id/button18"
            app:layout_constraintBottom_toBottomOf="@+id/button18"/>

        <Button
            android:text="@string/wednesday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:id="@+id/button18"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line" 
            app:layout_constraintStart_toEndOf="@+id/button17" 
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button14" 
            app:layout_constraintTop_toTopOf="@+id/button14"
            app:layout_constraintBottom_toBottomOf="@+id/button14"/>

        <Button
            android:id="@+id/button14"
            android:text="@string/thursday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line" 
            app:layout_constraintStart_toEndOf="@+id/button18" 
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button15" 
            app:layout_constraintTop_toTopOf="@+id/button15"
            app:layout_constraintBottom_toBottomOf="@+id/button15"/>

        <Button
            android:id="@+id/button15"
            android:text="@string/friday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line" 
            app:layout_constraintStart_toEndOf="@+id/button14" 
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button13" 
            app:layout_constraintTop_toTopOf="@+id/button13"
            app:layout_constraintBottom_toBottomOf="@+id/button13"/>

        <Button
            android:id="@+id/button13"
            android:text="@string/saturday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line" 
            app:layout_constraintStart_toEndOf="@+id/button15" 
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button6" 
            app:layout_constraintTop_toTopOf="@+id/button6"
            app:layout_constraintBottom_toBottomOf="@+id/button6"/>

        <Button
            android:id="@+id/button6"
            android:text="@string/sunday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line" 
            app:layout_constraintStart_toEndOf="@+id/button13" 
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/guideline28" 
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <android.support.constraint.Guideline
            android:id="@+id/guideline29"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="0dp"
            app:layout_constraintGuide_percent="0.5"/>

        <Button
            android:id="@+id/btn_cancel" 
            android:text="@string/cancel"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintHorizontal_bias="0.5" 
            app:layout_constraintEnd_toStartOf="@+id/btn_ok"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:background="@drawable/style_button_gray_line" 
            android:elevation="10dp"/>

        <Button
            android:id="@+id/btn_ok"
            android:text="@string/ok"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintStart_toEndOf="@+id/btn_cancel" 
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toEndOf="parent" 
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" 
            android:background="@drawable/style_button_gray_line"
            android:elevation="10dp"/>

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

PopupActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class PopupActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.popup);
    }

}

Manifest.xml

<activity
    android:name=".PopupActivity"
    android:theme="@android:style/Theme.Dialog" />

1 个答案:

答案 0 :(得分:0)

我检查了您的代码,您的代码很好。只需进行一些更改即可获得所需的输出。

您只需在第二个CheckedTextView中添加一行代码,即周末复选框。

android:checkMark="?android:attr/listChoiceIndicatorMultiple"

请尝试以下代码:

<?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="300dp"
    android:layout_height="150dp"
    android:background="@color/colorWhite">

    <android.support.constraint.Guideline
        android:id="@+id/guideline28"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="0dp"
        app:layout_constraintGuide_percent="0.6"/>

    <android.support.constraint.Guideline
        android:id="@+id/guideline22"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_begin="0dp"
        app:layout_constraintGuide_percent="0.2"/>

    <android.support.constraint.ConstraintLayout
        android:id="@+id/constraintLayout6"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline22"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <!-- this is the CheckedTextView -->
        <CheckedTextView
            android:id="@+id/checkedTextView2"
            android:text="@string/week"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceListItemSmall"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:visibility="visible"
            app:layout_constraintTop_toTopOf="@+id/checkedTextView3"
            app:layout_constraintBottom_toBottomOf="@+id/checkedTextView3"
            app:layout_constraintEnd_toStartOf="@+id/guideline23"
            app:layout_constraintStart_toStartOf="parent"/>

        <CheckedTextView
            android:id="@+id/checkedTextView3"
            android:text="@string/weekend"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceListItemSmall"
            android:checkMark="?android:attr/listChoiceIndicatorMultiple"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:visibility="visible"
            app:layout_constraintStart_toStartOf="@+id/guideline23"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

        <android.support.constraint.Guideline
            android:id="@+id/guideline23"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="0dp"
            app:layout_constraintGuide_percent="0.5"/>

    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="8dp"
        app:layout_constraintBottom_toTopOf="@+id/guideline28"
        app:layout_constraintTop_toBottomOf="@+id/constraintLayout6"
        android:id="@+id/constraintLayout7">

        <Button
            android:id="@+id/button16"
            android:text="@string/monday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button17"
            app:layout_constraintTop_toTopOf="@+id/button17"
            app:layout_constraintBottom_toBottomOf="@+id/button17"/>

        <Button
            android:id="@+id/button17"
            android:text="@string/tuesday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line"
            app:layout_constraintStart_toEndOf="@+id/button16"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button18"
            app:layout_constraintTop_toTopOf="@+id/button18"
            app:layout_constraintBottom_toBottomOf="@+id/button18"/>

        <Button
            android:text="@string/wednesday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:id="@+id/button18"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line"
            app:layout_constraintStart_toEndOf="@+id/button17"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button14"
            app:layout_constraintTop_toTopOf="@+id/button14"
            app:layout_constraintBottom_toBottomOf="@+id/button14"/>

        <Button
            android:id="@+id/button14"
            android:text="@string/thursday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line"
            app:layout_constraintStart_toEndOf="@+id/button18"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button15"
            app:layout_constraintTop_toTopOf="@+id/button15"
            app:layout_constraintBottom_toBottomOf="@+id/button15"/>

        <Button
            android:id="@+id/button15"
            android:text="@string/friday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line"
            app:layout_constraintStart_toEndOf="@+id/button14"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button13"
            app:layout_constraintTop_toTopOf="@+id/button13"
            app:layout_constraintBottom_toBottomOf="@+id/button13"/>

        <Button
            android:id="@+id/button13"
            android:text="@string/saturday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line"
            app:layout_constraintStart_toEndOf="@+id/button15"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/button6"
            app:layout_constraintTop_toTopOf="@+id/button6"
            app:layout_constraintBottom_toBottomOf="@+id/button6"/>

        <Button
            android:id="@+id/button6"
            android:text="@string/sunday"
            android:layout_width="30dp"
            android:layout_height="50dp"
            android:textColor="@color/colorRed"
            android:background="@drawable/style_button_red_line"
            app:layout_constraintStart_toEndOf="@+id/button13"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"/>

    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.ConstraintLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintTop_toBottomOf="@id/guideline28"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">

        <android.support.constraint.Guideline
            android:id="@+id/guideline29"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="0dp"
            app:layout_constraintGuide_percent="0.5"/>

        <Button
            android:id="@+id/btn_cancel"
            android:text="@string/cancel"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toStartOf="@+id/btn_ok"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:background="@drawable/style_button_gray_line"
            android:elevation="10dp"/>

        <Button
            android:id="@+id/btn_ok"
            android:text="@string/ok"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintStart_toEndOf="@+id/btn_cancel"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:background="@drawable/style_button_gray_line"
            android:elevation="10dp"/>

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>

希望它对您有用。