2014-01-22 19 views
0

我所做的一切都是改變背景的顏色,當我點擊列表項時,我不能再獲得效果。我需要改變什麼?的XML如下:我更改背景顏色後,我的ListView失去了它的行爲?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFFFFF"> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="centerCrop" 
     android:layout_margin="10dp" 
     android:src="@drawable/file" /> 

    <EditText 
     android:id="@+id/name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/image" 
     android:layout_marginTop="30dp" 
     android:layout_toRightOf="@+id/image" 
     android:background="@null" 
     android:includeFontPadding="true" 
     android:textColor="#000000" /> 


</RelativeLayout> 

所有我想要做的是有外觀爲以下,但顏色的變化,當我點擊列表項:
enter image description here

更新:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <ListView android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#FFFAF0" 
     android:dividerHeight="1dp" 
     android:layout_margin="0dp" 
     android:divider="#808080"/> 

</RelativeLayout> 
+0

你有沒有試過清潔項目? – DroidDev

+0

請發佈列表視圖的xml代碼 –

+0

@VishwasSharma我有。當我點擊時我收到通知,我不再看到列表視圖突出顯示當我這樣做 –

回答

1

那麼,什麼是I'do:
而不是使用固定的顏色作爲背景爲您定製的項目,就像在

android:background="#FFFFFF"> 

我會使用一個stelist繪製,如:

android:background="@drawable/item_states"> 

,當然,你需要在一個新的XML你drawable文件夾,稱爲什麼(我稱之爲item_states,在這個例子中)

<?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"/> <!-- pressed --> 
    <item android:state_focused="true" 
     android:color="#ff0000ff"/> <!-- focused --> 
    <item android:color="#ff000000"/> <!-- default --> 
</selector> 
+0

剛剛發現此問題:http://stackoverflow.com/questions/1521640/standard-android-button-with-a-different-color/1726352#1726352 =) –