Слова CheckBox и CheckedTextView не появляются - PullRequest
0 голосов
/ 22 мая 2019

Я сделал 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 голосов
/ 22 мая 2019

Я проверил твой код, твой код в порядке. Для достижения желаемого результата необходимы лишь некоторые изменения.

Вам нужно добавить только один строчный код во второй 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>

Я надеюсь, что это сработает для вас.

...