【问题标题】:ListView longpress custom colorListView 长按自定义颜色
【发布时间】:2015-07-24 18:44:57
【问题描述】:

我想在 AppCompat 主题中按下列表视图项时自定义长按颜色和动画。我正在使用自定义选择器。

这里是 list_selector_background_transition:

 <?xml version="1.0" encoding="utf-8"?>
    <transition xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/list_selector_background_pressed"  />
    <item android:drawable="@drawable/list_selector_background_longpress"  />
    </transition>

长按时不工作。

    <?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:endColor="@color/primary"
                android:startColor="@color/accent"
                android:angle="270" />
        </shape>
    </item>
</selector>

应该怎么做?

编辑。 item_selector.xml

  <item android:state_window_focused="false" android:drawable="@android:color/transparent" />

<item android:state_focused="true"  android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true"  android:state_enabled="false"                              android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true"  android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true"  android:drawable="@drawable/list_selector_background_focus" />

【问题讨论】:

  • 那么你在哪里使用你的list_selector_background_transition
  • 在 item_selector 中,它是行布局中的背景。
  • 那么渐变的东西是什么?
  • pressed 和 longpress 的颜色值是多少?
  • 我试图重复从浅蓝色到深蓝色的发光效果,只是改变颜色。我做错了什么?

标签: android listview styles


【解决方案1】:

也许this 会帮助你。

我猜你需要记住 :state 焦点标签

<item android:state_focused="true"/>

【讨论】:

  • 我在每一行都有 state_focused。
【解决方案2】:

我认为您的问题是您创建了一个列表选择器并将其用作背景。列表选择器将优先于背景。你应该在你的ListView 上将它设置为listSelector

<ListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:listSelector="@drawable/item_selector" />

【讨论】:

  • 这有助于以某种方式进一步发展,但这不是我所要求的。如何更改 AppCompat 的长按动画颜色
  • 您的问题到底是什么?你是说长按不起作用,现在你说的是颜色定制?
  • 长按正在工作,颜色不像默认情况下那样工作。我参考这个问题stackoverflow.com/questions/6513301/…
  • 所以你是说你的行为与没有选择器时的行为完全相同?
  • 完全一样,是的。没有动画。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多