【问题标题】:Android Selector ProblemAndroid 选择器问题
【发布时间】:2010-03-05 11:03:00
【问题描述】:

我有一个带有自定义 item_row.xml 的列表视图。我以这种方式定义了一个选择器:

<?xml version="1.0" encoding="utf-8"?>

<item
    android:state_pressed="false"
    android:drawable="@drawable/list_bg" >
</item>
<item 
    android:state_pressed="true"
    android:drawable="@drawable/header_bg" >
</item>
<item
    android:state_focused="false"
    android:drawable="@drawable/list_bg" >
</item>
<item
    android:state_focused="true"
    android:drawable="@drawable/header_bg">
</item>

然后这样放入item_row.xml:

    <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="70dip"
  android:orientation="vertical"
  android:background="@drawable/list_selector"> 

我想要两件事:

  • 当我用箭头键移动时,选中的项目改变了它的背景。它适用于选择器的实际实现。
  • 当我按下一个项目时,该项目的背景也发生了变化,但它不适用于实际的选择器。

有什么想法吗?我也尝试设置到 ListView android:listSelector="@drawable/list_selector" 但它也不起作用。

谢谢

【问题讨论】:

    标签: android listview selector


    【解决方案1】:

    您应该将StateListDrawable 建模为Android 本身用于ListView 选择器的那个。您可以在$ANDROID_HOME/platforms/$VERSION/data/res/drawable/list_selector_background.xml 中找到它,其中$ANDROID_HOME 是安装Android SDK 的位置,$VERSION 是某个Android 版本(例如android-2.1)。然后,通过布局 XML 中的 ListView 中的 android:listSelector 应用列表选择器。

    【讨论】:

    • 现在我的选择器工作正常,但问题是.. 如果我有 item_row_list 的背景,选择器不会出现。而且我不能放在首位,因为它涵盖了行的信息.. 谢谢!
    • 使选择器透明或半透明,放在上面。
    • 还是不行。如果我使用 我看不到选择器,它也覆盖了文本。我想要的是: - 当我用箭头键沿着列表移动并按下一个项目时,看到一个选择器透明。如果您能帮助我,我将不胜感激
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-03
    • 1970-01-01
    • 2011-04-04
    • 2011-10-31
    • 2013-09-22
    相关资源
    最近更新 更多