Свойства :hover :active в Android style

Рейтинг: 0Ответов: 1Опубликовано: 12.11.2014

Привет. Есть ли в Android что-то подобное :hover :active(css)? Как этим пользоваться?

Ответы

▲ 1

Селекторы. Пишите что-то вроде, к примеру, в res/color/test.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:color="#ffff0000"/> <!-- нажата -->
    <item android:state_focused="true"
          android:color="#ff0000ff"/> <!-- фокус -->
    <item android:color="#ff000000"/> <!-- дефолтный цвет -->
</selector>

А потом, например, у кнопки в поле textColor подставляете:

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:textColor="@color/test" />