0

我正在尝试创建可点击的文本框,在按下时像列表视图项一样突出显示。我有自己想要使用的背景图片,所以我无法使用

android:background="?android:attr/selectableItemBackground"

当我在使用我自己的背景图像作为文本框的同时单击文本框时,有没有一种方法可以实现蓝色的“发光”效果?目前,我的文本视图看起来像:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/title"
          style="@style/ListSeparatorTextViewStyle"
          android:paddingLeft="10dip"
          android:paddingRight="10dip"
          android:focusable="true"/>

更新:

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

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:background="?android:attr/selectableItemBackground"
          android:state_pressed="true" />

    <item android:drawable="@drawable/list_section_divider_holo_custom"></item>
</selector>
4

1 回答 1

1

您可以为 textview 的背景创建一个可绘制对象,如下所示

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item   android:state_pressed="true" ><!-- this drawable display when you press textView -->
<shape  android:shape="rectangle" >
<gradient android:startColor="#fa7905"
          android:endColor="#fcc96b"
          android:angle="90"
></gradient>
</shape>
</item>

<item android:drawable="your drawable">
<!-- this drawable show when you dont press textview -->
</item>

</selector>
于 2013-08-09T13:50:41.467 回答