Android: TextColor не работает для TextView - PullRequest
0 голосов
/ 27 февраля 2019

android:textColor не похоже на TextView внутри вложенного LinearLayout.Я посмотрел на вопрос в Селектор Colorcolor не работает .Но это также не работает в моем случае.Вот мой файл макета:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".CreateActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="15dp">

        <TextView
            android:id="@+id/lblTitle"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            android:layout_weight="0.9"
            android:hint="Title:"
            android:textAlignment="textEnd"
            android:textSize="24sp"
            android:textColor="#000000"/>

        <EditText
            android:id="@+id/lblTitleEdit"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp"
            android:hint="Enter your title here"
            android:layout_weight="0.4"
            android:inputType="text"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="15dp">

        <TextView
            android:id="@+id/lblVenue"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            android:layout_weight="0.9"
            android:hint="Venue:"
            android:textAlignment="textEnd"
            android:textSize="24sp"
            android:textColor="#000000"/>

        <EditText
            android:id="@+id/lblVenueEdit"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp"
            android:hint="Enter your venue here"
            android:layout_weight="0.4"
            android:inputType="text"/>

    </LinearLayout>
</LinearLayout>

Я здесь ошибаюсь?Любая помощь будет принята с благодарностью.

Ответы [ 7 ]

0 голосов
/ 27 февраля 2019

Вот что вы устанавливаете в текстовом представлении - текст подсказки.Итак, вам нужно установить textColorHint свойство text-view.

То, что вы делали, это установить цвет текста.Что не будет работать, потому что вы не ввели текст в текстовом режиме.

     <TextView
        android:id="@+id/lblTitle"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        android:layout_weight="0.9"
        android:hint="Title:"
        android:textAlignment="textEnd"
        android:textSize="24sp"
        android:textColorHint="#000000"/>
0 голосов
/ 27 февраля 2019

Согласно вашему коду, вы написали подсказку в Textview, поэтому для применения цвета в подсказке используйте, например,

android:textColorHint="#000000"

Или, если вы хотите использовать цвет текста, вы должны установить текст в Textview.как показано ниже:

android:text="Title:"
android:textColor="#000000"

Если вы используете подсказку в TextView, используйте следующее:

android:hint="Title:"
android:textColorHint="#000000"
0 голосов
/ 27 февраля 2019

Вы пытаетесь задать цвет текста для android: hint и заменить его на android: text.

См. Ответ ниже

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".CreateActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="15dp">

        <TextView
            android:id="@+id/lblTitle"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            android:layout_weight="0.9"
            android:text="Title:"
            android:textAlignment="textEnd"
            android:textSize="24sp"
            android:textColor="#000000"/>

        <EditText
            android:id="@+id/lblTitleEdit"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp"
            android:hint="Enter your title here"
            android:layout_weight="0.4"
            android:inputType="text"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="15dp">

        <TextView
            android:id="@+id/lblVenue"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            android:layout_weight="0.9"
            android:text="Venue:"
            android:textAlignment="textEnd"
            android:textSize="24sp"
            android:textColor="#000000"/>

        <EditText
            android:id="@+id/lblVenueEdit"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp"
            android:hint="Enter your venue here"
            android:layout_weight="0.4"
            android:inputType="text"/>

    </LinearLayout>
</LinearLayout>
0 голосов
/ 27 февраля 2019

Для android:text="Title:" вы должны использовать android:textColor="#000000"

И

Для android:hint="Title:" вы должны использовать android:textColorHint="#000000"

Happy Coding.

0 голосов
/ 27 февраля 2019

Пожалуйста, отметьте это

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".CreateActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="15dp">

        <TextView
            android:id="@+id/lblTitle"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            android:layout_weight="0.9"
            android:text="Title:"
            android:textAlignment="textEnd"
            android:textSize="24sp"
            android:textColor="#000000"/>

        <EditText
            android:id="@+id/lblTitleEdit"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp"
            android:hint="Enter your title here"
            android:layout_weight="0.4"
            android:inputType="text"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="15dp">

        <TextView
            android:id="@+id/lblVenue"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            android:layout_weight="0.9"
            android:text="Venue:"
            android:textAlignment="textEnd"
            android:textSize="24sp"
            android:textColor="#000000"/>

        <EditText
            android:id="@+id/lblVenueEdit"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginLeft="10dp"
            android:hint="Enter your venue here"
            android:layout_weight="0.4"
            android:inputType="text"/>

    </LinearLayout>
</LinearLayout>
0 голосов
/ 27 февраля 2019

Добавить Android: текст, вы даете свойство подсказки и пытаетесь изменить цвет текста

android: text = "Название:"

0 голосов
/ 27 февраля 2019

Вы использовали подсказку в качестве текста здесь.Таким образом, вы должны применить цвет к вашей подсказке с помощью следующего кода.или вы можете также изменить подсказку на текст в вашем xml.

android:textColorHint="#000"
...