首页 > 解决方案 > 标签没有显示出来

问题描述

这是我的界面在 Android Studio 中的样子:

在此处输入图像描述

这是我在真实设备中的界面:

在此处输入图像描述

为什么标签没有显示出来,我什至不能改变EditText背景颜色?

这是我的一些代码 XML 文件,我正在使用的以下部分和我正在使用ScrollView的颜色部分相对布局。这两种布局都在一个CardView.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/card_view"

<ScrollView
    android:layout_width="match_parent"
    android:layout_marginTop="235dp"
    android:layout_height="wrap_content"
    android:fillViewport="true">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="20dp"
        android:orientation="vertical"
        android:background="@color/transparent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="@color/transparent">


            <studio.carbonylgroup.textfieldboxes.TextFieldBoxes
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:labelText="Email"
                app:hasClearButton="true">

                <studio.carbonylgroup.textfieldboxes.ExtendedEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="8dp"
                    android:inputType="textEmailAddress"
                    android:id="@+id/input_email"/>

            </studio.carbonylgroup.textfieldboxes.TextFieldBoxes>



        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:orientation="vertical"
            android:background="@color/transparent">

            <studio.carbonylgroup.textfieldboxes.TextFieldBoxes
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:labelText="Username"
                app:hasClearButton="true">

                <studio.carbonylgroup.textfieldboxes.ExtendedEditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/input_name"
                    android:inputType="textPersonName"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="8dp"/>

            </studio.carbonylgroup.textfieldboxes.TextFieldBoxes>

        </LinearLayout>

标签: androidandroid-studioandroid-layout

解决方案


注意以下几行:

    xmlns:app="http://schemas.android.com/tools"
    ...

    app:labelText="Username"  //app is a tool namespace, so label text only shown in preview

修改为:

    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    ...

    app:labelText="Username"

推荐阅读