如何在android中利用Theme設定application 的所有listview的style?~

來源:互聯網
上載者:User

標籤:android   style   color   檔案   io   cti   

今天看VLC的原始碼,發現一個很神奇的東西

所有listview的點擊效果背景色都是橘黃色

花了點時間找了一下看看怎麼實現的。

首先,定義一個<selector>

like this:

<selector>

  <item android:state_pressed="true">      

    <shape android:shape="rectangle">

      <solid android:color="@color/orange">

    </shape>

  </item>

</selector>

當然,你也可以直接找一張橘黃色的圖片,效果和上面是一樣的

然後你可以建一個style,這個style可以包含你希望的listview的所有屬性,這裡只舉例說明,所以唯寫了一個android:listselector

<style name="theme.list">

  <item name="android:listselector">@drawable/一張圖片 or 上面那個selector對應的xml,放在drawable檔案夾下即可~ </item>

</style>

 

把這個style放到大的theme定義中,like this:(紅字表示繼承,因為畢竟我們只修改了一個大的theme中的一部分)

<style name="Theme.APPLICATION" parent="Theme.sherlock.Light">

<item name="listviewStyle">@style/theme.list</item>

</style>

最後把這個theme放到你的activity的android:theme中,這樣你的那個activity所有的listview(包括子fragment)都是這個style 了~

<Activtiy

android:theme="@style/Theme.APPLICATION"

>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.