2017-04-27 93 views
0

我想看到突出顯示,當我單擊ListView中的項目,但它不起作用。我搜索了很長時間來解決這個問題,但沒有任何幫助。如何突出顯示在Xamarin中的ListView項目Android

我在創建Android本機列表時沒有任何問題。 這是在Android本地項目上工作的佈局的XML。

<ListView 
      android:id="@+id/menuList" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/img_logo_arkema" 
      android:layout_below="@+id/img_logo_paladin" 
      android:background="#ffffffff" 
      android:choiceMode="singleChoice" /> 

但是,這不起作用,當我在Xamarin.Android項目中創建相同的ListView。 以下是Xamarin.Android項目無法使用的佈局XML。

<ListView 
     android:id="@+id/menuList" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="@color/colorTopDivider" 
     android:dividerHeight="@dimen/right_menu_divider_size" 
     android:choiceMode="singleChoice" /> 

我開發的Xamarin.Android在Visual Studio 2015年

感謝您的幫助!

+0

您是否收到任何錯誤消息?你能不能發佈你的適配器的代碼? –

+0

感謝您的回覆,貓王。我沒有收到任何錯誤消息。 –

回答

0

呀基本上你的想法是正確的Passionate.C。但你也可以讓它更容易選擇,可以定義XML中的選擇(在drawble文件夾中)

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_pressed="true" 
    android:drawable="@android:drawable/list_selector_background" />  
</selector> 

然後在你的ListView你打電話setSelector(),並通過自己的選擇。這是一個更可定製的解決方案,因爲您還可以輕鬆控制listView項目的其他狀態

+1

我同意Maurizio。這是更可定製的解決方案。但我不想爲基本亮點創建新的資源。謝謝。 –

相關問題