Приложение Android падает из-за TextColor в main.xml

1

Я разработал базовую страницу действий пользовательского интерфейса в Android с TextView и EditText и кнопку. Я установил для TextView textColor какое-то шестнадцатеричное значение, и из-за этого мое приложение вылетает. Если я удалю этот textColor, это означает, что приложение работает отлично. Target SDK = 2,3, вот код

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical|center_horizontal"
    android:orientation="vertical"
    android:padding="15dp">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:text="Enter search Key"
        android:textColor="#ff3300"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/searchkey"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Search Key ..." />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button" />
</LinearLayout>

Можем ли мы установить textColor для TextView или что-то еще не так с кодом.

Заранее спасибо...

  • 0
    краш журнал пожалуйста ..
  • 0
    это работает нормально для меня ..
Показать ещё 1 комментарий
Теги:
android-edittext
textview
textcolor

1 ответ

3
Лучший ответ

Вам нужно определить цвет в файле ресурсов в папке res/values

<resources>
<color name="mycolor">#33b5e5</color>
</resources>

И укажите с помощью @color/mycolor в файле макета

<TextView
    android:id="@+id/textView"
    android:layout_gravity="left"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="Enter search Key"
    android:textColor="@color/mycolor"
    android:textStyle="bold" />
  • 0
    Это сработало. Спасибо :), проблема с одним моим, я упомянул значения цвета в маленькой букве, например. ff3300 вместо FF3300 в любом случае спасибо за помощь :)

Ещё вопросы

Сообщество Overcoder
Наверх
Меню