How to use theme in Android to set application for all ListView style?~

Source: Internet
Author: User

Look at the source code of VLC today and find a very magical thing

All ListView's Click effect Background color is orange color

It took some time to find out how to make it come true.

First, define a <selector>

Like this:

<selector>

<item android:state_pressed= "true" >

<shape android:shape= "Rectangle" >

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

</shape>

</item>

</selector>

Of course, you can also directly find a picture of orange, the effect is the same as above

Then you can build a style, which can contain all the properties of the ListView you want, just for example, so only one android:listselector is written.

<style name= "Theme.list" >

<item name= "Android:listselector" > @drawable/a picture or the selector corresponding XML, placed in the Drawable folder can ~ </item>

</style>

Put this style into a large theme definition, like this: (The Scarlet letter means inheritance, because we only modified a part of a large theme)

<style name= "theme.application" parent= "Theme.sherlock.Light" >

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

</style>

Finally put this theme into your activity's android:theme so that all your activity's ListView (including fragment) is the style.

<activtiy

Android:theme= "@style/theme.application"

>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.