2014-12-18 58 views
2

我有一個TabHost項目,我希望它們只在點擊時突出顯示。列表視圖項目在點擊時突出顯示(不需要)

我收到了它,我的列表視圖本身,而是對TabHost什麼也沒有改變(我認爲這不應該的問題。)

<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" 
    tools:context="at.htl3r.appmosphere.MainActivity$PlaceholderFragment" > 

    <TabHost 
     android:id="@android:id/tabhost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 
      </TabWidget> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" > 

       <ListView 
        android:id="@+id/tab1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </ListView> 

       <ListView 
        android:id="@+id/tab2" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </ListView> 

       <ListView 
        android:id="@+id/tab3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </ListView> 

       <ListView 
        android:id="@+id/tab4" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </ListView> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 
</RelativeLayout> 

我看了一些帖子如何禁用它,但I don't want to disable it complete因爲我會處理點擊動作

我嘗試添加choiceMode="none"selector

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

    <item android:drawable="@color/darkgreen_light" android:state_pressed="true"/> 
    <item android:drawable="@android:color/transparent" android:state_activated="true"/> 
    <item android:drawable="@android:color/transparent" android:state_checked="true"/> 
    <item android:drawable="@android:color/transparent" android:state_selected="true"/> 
    <item android:drawable="@android:color/transparent"/> 

</selector> 

UPDATE

更好的選擇:ViewPagerIndicator

回答

1

你應該讓你的列表視圖的選擇模式單一的選擇(以能夠檢測項目selectsions /抽頭),和舊版本的覆蓋列表選擇是透明的(@null作品安卓但不16+):

<style name="YourTheme.ListView" parent="@android:style/Widget.ListView"> 
    <item name="android:listSelector">@drawable/listSelector</item> 
    <item name="android:choiceMode">singleChoice</item> 
</style> 

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

在您listSelector.xml看起來是這樣的:

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

    <item android:drawable="@color/darkgreen_light" android:state_pressed="true"/> <!-- pressed --> 
    <item android:drawable="@color/darkgreen_light" android:state_focused="true"/> <!-- focused --> 
    <item android:drawable="@android:color/transparent"/> <!-- default --> 

</selector> 

更新

如果你不希望在項目點擊任何視覺反饋,只需在列表視圖的風格改變@drawable/listSelector@android:color/transparent

+0

我只想處理onclicks而不是選擇;不會改變任何東西... 仍然選擇被點擊的項目.. – rala 2014-12-19 10:33:11

+0

請參閱我的更新 – rekaszeru 2014-12-19 10:41:52

+0

我的意思是它不應該是恆定的,如果我點擊它應該只在印刷過程中突出顯示,但不能 – rala 2014-12-19 10:51:49

相關問題